RecordSource with parameters

  • Thread starter Thread starter Michel
  • Start date Start date
M

Michel

Hi,
I'd like to put in the RecordSource of the form a sql who refer to a
variable defined as public.
Somethings like this

select * from myTable where val = myModule.myPublicVar

Is this possible?
Do I have to use a special syntax?

Michel
 
You can't refer to a variable directly from the query, but you can call a
VBA function that returns the result of the query ...

Public SomeVariable As Variant

Public Function GetTheValue() As Variant
GetTheValue = SomeVariable
End Function

SELECT SomeField, GetTheValue() AS TheValue FROM SomeTable

This only works in Access, though - it won't work if you try to use that
query from another, non-Access application.
 
Back
Top