Okay, so I'm using a form to launch a query and I need this query to set the criteria based on what is being viewed in the form. I've researched and found that in order to use a variable in a query, you have to pass it to a function.
Here's my code for the form that sets the variable:
And here is my function:
Here is what I have as my criteria in my query:
I've verified that the variable (txtModelClass) gets set correctly in the Sub by displaying a message box but my query keeps returning blank.
What am I doing wrong?
Here's my code for the form that sets the variable:
Code:
Private Sub cmdClassReport_Click()
Dim txtModelClass As String
'uses open form to lookup info in related table and set the variable
txtModelClass = Nz(DLookup("[fleetModelClass]", "tblFleetCopiers", "[fleetAutoID] =" & Me!locFleetIDAuto), 0)
GetModelClass txtModelClass
DoCmd.OpenQuery "qryCopiers"
End Sub
And here is my function:
Code:
Public Function GetModelClass(ByVal txtModelClass As String) As String
'variable set in Sub used as value of function
GetModelClass = txtModelClass
End Function
Here is what I have as my criteria in my query:
Code:
GetModelClass("«txtModelClass»")
I've verified that the variable (txtModelClass) gets set correctly in the Sub by displaying a message box but my query keeps returning blank.
What am I doing wrong?