How could I put variables from modules to RecordSource Query?

bad-aries

New member
Local time
Today, 13:45
Joined
Jul 16, 2010
Messages
9
Hi all,
My problem is that the report needs to process the variables in the Open event and make the RecordSource. If I use something.recordsource in the module, I couldn't choose which field to display in the Report Design View. So I would put that query directly in the RecordSource property directly.


tID is a table field
vID is a variable defined in the Open Event of a Report.

The below things were tried but they all don't work:
Select * from tableA where PID = me.vID

Select * from tableA where PID = reportName.FunctionName.vID

Select * from tableA where PID = Forms!ReportName.vID

So how could I make that work?

Thanks in advance.
 
SELECT * FROM tableA WHERE PID = Reports!reportname.controlname
----------

Queries do not have direct access to variables.
You can use a function to return the variable value from the name.

SELECT * FROM tableA WHERE PID = Somefunction()

The function simply sets the return value to the variable.
-------------

Write the sql string in VBA and set it as the Record Source property of the Report.

strsql = "SELECT * FROM tableA WHERE PID =" & somevariable
Me.RecordSource = strsql
------------

In A2007 you can use TempVars to put a variable into a query.

http://msdn.microsoft.com/en-us/library/bb257083(office.12).aspx
 
SELECT * FROM tableA WHERE PID = Reports!reportname.controlname
----------

Queries do not have direct access to variables.
You can use a function to return the variable value from the name.

SELECT * FROM tableA WHERE PID = Somefunction()

The function simply sets the return value to the variable.
-------------

Write the sql string in VBA and set it as the Record Source property of the Report.

strsql = "SELECT * FROM tableA WHERE PID =" & somevariable
Me.RecordSource = strsql
------------

In A2007 you can use TempVars to put a variable into a query.

http://msdn.microsoft.com/en-us/library/bb257083(office.12).aspx

Thank You so much.
 

Users who are viewing this thread

Back
Top Bottom