psycoperl
Active Member
- Joined
- Oct 23, 2007
- Messages
- 339
- Office Version
- 365
- 2016
- Platform
- Windows
- MacOS
- Web
HI All, I am getting a VB runtime error when I am running a function (Code Below)
The Error is Runtime Error -2147217900 (800040e14): The SELECT statement includes a reserved word or an argumetn name that is misspelled or missing, or the punctuation is incorrect.
When I run the query in Access's Query Builder, it runs without error.
Can you please provide some guidance.
Thanks
The Error is Runtime Error -2147217900 (800040e14): The SELECT statement includes a reserved word or an argumetn name that is misspelled or missing, or the punctuation is incorrect.
When I run the query in Access's Query Builder, it runs without error.
Can you please provide some guidance.
Thanks
Code:
Function CheckIfCurrentATBAppointmentIsPending(StudentID As String, NearestATB As Integer) As Boolean
Dim Flag As Boolean
Dim ATBsql As String
ATBsql = "SELECT MATBS.MaxAppt, ATBS.ATBSession AS SID" & _
"FROM (SELECT tblATBAppointment.StudentID, Max(tblATBAppointment.AppointmentID) AS MaxAppt " & _
" FROM tblATBAppointment " & _
" GROUP BY tblATBAppointment.StudentID) AS MATBS " & _
"INNER JOIN tblATBAppointment AS ATBS ON MATBS.MaxAppt = ATBS.AppointmentID " & _
"WHERE (((MATBS.StudentID)='" & StudentID & "'));"
Flag = False
Dim ATBAppt As ADODB.Recordset
Set ATBAppt = New ADODB.Recordset
ATBAppt.ActiveConnection = CurrentProject.Connection
ATBAppt.CursorType = adOpenDynamic
ATBAppt.LockType = adLockOptimistic
ATBAppt.Open ATBsql
If Not ATBAppt.BOF Then
ATBAppt.MoveFirst
End If
If ATBAppt.BOF And ATBAppt.EOF Then
'If there are no records, return False to allow scheduling
Flag = False
ElseIf ATBAppt![SID] < NearestATB Then
'If the returned record is prior to the date of the nearest ATB, return False to allow scheduling
Flag = False
Else
Flag = True
End If
ATBAppt.Close
Set ATBAppt = Nothing
CheckIfCurrentATBAppointmentIsPending = Flag
End Function