pauljkeenan
Programmer
Hi Guys
Im getting unusual errors when tryint to search for records between two reference numbers. Here is the code for search
Private Sub cmdShowRefRecs_Click()
Dim strSQL1 As String, strOrder1 As String, strWhere1 As String
strSQL1 = "SELECT qrySearchVisaSub.Ref_No, qrySearchVisaSub.Name, qrySearchVisaSub.App_Date, qrySearchVisaSub.Issue_Date, qrySearchVisaSub.Visa_Type, qrySearchVisaSub.Fee, qrySearchVisaSub.Currency, qrySearchVisaSub.Del_Sanc, qrySearchVisaSub.Nationality, qrySearchVisaSub.DateOfBirth, qrySearchVisaSub.Passport_No, qrySearchVisaSub.Sticker_No " & _
"FROM qrySearchVisaSub"
strWhere1 = "WHERE"
strOrder1 = "ORDER BY qrySearchVisaSub.Ref_No;"
If Not IsNull(Me.fromRefNo) And Not IsNull(Me.toRefNo) Then
strWhere1 = strWhere1 & " (qrySearchVisaSub.Ref_No) between '*" & Me.fromRefNo & "*' and '*" & Me.toRefNo & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere1 = Mid(strWhere1, 1, Len(strWhere1) - 5)
'Pass the SQL to the RowSource of the listbox
Me!frmVisaSearchSub.Form.RecordSource = strSQL1 & " " & strWhere1 & "" & strOrder1
Me!frmVisaSearchSub.Form.Requery
End Sub
I think it must have something to do with the between statement itself, because when I moved the final "AND" out a space I got a syntax error, when I move it back in a space, I get "you cancelled the previous operation" error.
Is the syntax correct then for such a search?
Thanking you in advance
Im getting unusual errors when tryint to search for records between two reference numbers. Here is the code for search
Private Sub cmdShowRefRecs_Click()
Dim strSQL1 As String, strOrder1 As String, strWhere1 As String
strSQL1 = "SELECT qrySearchVisaSub.Ref_No, qrySearchVisaSub.Name, qrySearchVisaSub.App_Date, qrySearchVisaSub.Issue_Date, qrySearchVisaSub.Visa_Type, qrySearchVisaSub.Fee, qrySearchVisaSub.Currency, qrySearchVisaSub.Del_Sanc, qrySearchVisaSub.Nationality, qrySearchVisaSub.DateOfBirth, qrySearchVisaSub.Passport_No, qrySearchVisaSub.Sticker_No " & _
"FROM qrySearchVisaSub"
strWhere1 = "WHERE"
strOrder1 = "ORDER BY qrySearchVisaSub.Ref_No;"
If Not IsNull(Me.fromRefNo) And Not IsNull(Me.toRefNo) Then
strWhere1 = strWhere1 & " (qrySearchVisaSub.Ref_No) between '*" & Me.fromRefNo & "*' and '*" & Me.toRefNo & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere1 = Mid(strWhere1, 1, Len(strWhere1) - 5)
'Pass the SQL to the RowSource of the listbox
Me!frmVisaSearchSub.Form.RecordSource = strSQL1 & " " & strWhere1 & "" & strOrder1
Me!frmVisaSearchSub.Form.Requery
End Sub
I think it must have something to do with the between statement itself, because when I moved the final "AND" out a space I got a syntax error, when I move it back in a space, I get "you cancelled the previous operation" error.
Is the syntax correct then for such a search?
Thanking you in advance