Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I set a report's Record Source property in code 1

Status
Not open for further replies.

danielemc2

Programmer
Apr 23, 2002
4
US
I need to assign a query to a report at run time. I've got the name of the report so I can OpenReport it. Ive tried to set the query at runtime with.
dim query2run,report2prt
query2run = "Name of some query from existing queries"
report2prt = "Name of some report from existing reports"
DoCmd.OpenReport report2prt, acViewPreview , query2run
'but this doesn't work

so now i'd like to just set the Record Source property of the report.
but how?
 
In the on open event of the report. You can equate to the me.recordsource in the onopen event anything that resolves to an SQL select statement.

sub form_OnOpen()

me.recordsource = "query2run"
or
me.recordsource = "Select what ever from yourtable"

end sub
 
Thanks, that works, but how can I reference my form's public variable that I need to set it to?
 
Instead of a public variable in the Form, put the public variable in the standard module and then you can reference it anyplace in the application. Another way is to create a public function and have the function return the variable.

i.e.
in standard module
Option explicit
Public myvar integer

Public Function myfunc() as integer
myfunc = myvar
End Function

in your report onopen
me.recordsource = "select * from tab where tabvar = " & myvar

or

me.recordsource = "select * from tab where tabvar = " & myfunc()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top