Passing parameters to a single query from either of two forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Have two forms that are based on the same query. Want to pass parameters
from either FormA or FormB to the query (e.g., SalesDate). Tried "Oring" the
forms in Date criteria (e.g., Forms!FormA!SalesDate Or
Forms!FormB!SalesDate). But this did not work. I'm trying to avoid using
two separate queries. Any ideas.
 
Below is a function that will allow you to do what you want. A Static
Function will retain it's variables values between calls. The way the
function below works, is that if you pass it a value, it will store the value
in the variable lngParm. If you do not, it will retain the value it had
before the call. So, in your form code, pass it the value you want to use in
the query. Use the function in your query, but don't pass it a value. It
will return the value passed in the form. This way, the query doesn't know
or care where the value came from.

To use it in your query, put something like this in the query builder where
you would put field name:

SomeName: GetQueryParm()

To use it in your forms, put somethingk like:

Dim lngNotUsed as Long

lngNotUsed = GetQueryParm(Me!SomeControl)

Static Function GetQueryParm(Optional varParm As Variant) As Long
Dim lngParm As Long

If Not IsMissing(varParm) Then
lngParm = CLng(varParm)
End If
GetQueryParm = lngParm
End Function
 
Back
Top