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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing a record source

Status
Not open for further replies.

Dryseals

Technical User
Oct 17, 2002
38
US
I have a form that allows the users to make multiple selections and type in variables that allow them to do a search. When they click the search button, I build an sql string and use it as the recordsource of a form that opens with their results. On rare occasions the user would like to print out the results of the search as a report. How can I use this string as the record source for the report without retyping the code in the report?

I thought about making the string a public variable, but it is obvious that I do not understand how to do this(no formal training).
 
Hi
If I have understood your problem, this might work for you:
Code:
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Forms!frmSearchForm.RecordSource
End Sub

In other words, set the report RecordSource from the form RecordSource.
 
Thank you, sometimes the simplest way is the best, I don't know why I didn't think of the on open statement.

It would still be nice to know how to put this string in a variable that can be used anywhere.
 
Hi
You may wish to look at this:
Code Modules, Object Modules, and Scoping
faq705-5319
It is by CajunCenturion and has a lot of useful information on variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top