Hello all,
I am attempting to create a dynamic query based on form driven criteria using VBA. I found a few tutorials out there, but I'm receiving an error saying
Run-time error '13':
Type mismatch.
Here is the code I am using
When I try to run using just one criteria "RetestLocation" or "CustomerName", it returns results. Its only when I try to use two or more criteria I get the error.
Both fields are Short Text Data Types in the table. The form uses drop boxes for both fields.
Any help would be appreciated!
I am attempting to create a dynamic query based on form driven criteria using VBA. I found a few tutorials out there, but I'm receiving an error saying
Run-time error '13':
Type mismatch.
Here is the code I am using
Code:
Private Sub cmd_RunQuery_Click()
Dim strsql As Variant
Dim qbf As QueryDef
strsql = "SELECT * FROM WorkOrderLogAll WHERE RetestLocation =" & "'" & Forms!CustomerRetestDatabaseSearch!RetestLocation & "'" And CustomerName = " & " '" & Forms!CustomerRetestDatabaseSearch!CustomerName & "'"
Set qbf = CurrentDb.CreateQueryDef("DynamicQuery", strsql)
DoCmd.OpenQuery qbf.Name
Set qdf = Nothing
Set db = Nothing
End Sub
Both fields are Short Text Data Types in the table. The form uses drop boxes for both fields.
Any help would be appreciated!