Passing a variable to a saved query.

GaryInMilwaukee

New member
Local time
Today, 15:43
Joined
Jul 23, 2010
Messages
5
Ok, I've tried looking and doing searches for the answer to this question but I have not yet found the solution:

This sub is tied to a button on a form.

Private Sub Command26_Click()

Dim lLocalVariable As String
lLocalVariable = "Brandi"
docmd.OpenQuery "First_Name"

End Sub

I want to pass the ILocalVariable to a saved query under the [first_name] field. Any ideas? What is the verbiage used in the saved query (First_Name) in that field (ex. 'ILocalVariable')?
 
Last edited:
You can't refer to a variable from a query. The usual workaround is to create a public function that returns the value of the variable (which should also be declared in a standard module so it's available everywhere). With the function, you simply call it:

WHERE FieldName = FunctionName()
 
You might be able to mimick it by using an InputBox() and applying the sql string to the querydef. But that's not a neat way of doing things. Just fyi.
 

Users who are viewing this thread

Back
Top Bottom