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

Use form to set record source for report 1

Status
Not open for further replies.

krets

Technical User
Dec 29, 2006
214
US
I built a form with some VB code in the background that dynamically sets the record source by concatenating values in combo boxes. The VB code ends up declaring a variable called "myRecordSource" and then setting the form's source to that variable. (Thank you faq702-1177.)

Now I would like the user to be able to click a button that would open a report that uses the same record source as the form is currently using. How could I go about doing that?
 
Howdy krets . . .

Perhaps the following in the [blue]Open[/blue] event of the report
Code:
[blue]   Me.RecordSource =Forms!FormName.RecordSource
or
   Me.RecordSource = myRecordSource
[/blue]
Note: the form or variable has to be in scope at the time of assignment.

Calvin.gif
See Ya! . . . . . .
 
set the onload or current event for you second form to have the following event procedure.

myform = the name of form being opened with the dynamic sql statement.


Private Sub Form_Activate()
'if myRecordSource is a variant
if not isnull(myRecordSource) then
'or if myRecordSource is string
if myRecordSource <> "" then
Forms!myform.RecordSource = myRecordSource
me.requery
endif
End sub
 
Ah, I think I see my problem. I was referring to the record source of the main form when it's the source of the subform that I need.

If the subform is called frmTechTotals and the main form is called frmMgrTechTotals how would I reference that?
 
NM, I didn't notice a typo in my VB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top