Change Report RecordSource at Runtime

P

Paul Mars

MainForm has many different Buttons to open the same "MainData" Form with
different RecordSources using:

Private Sub RecordsAddressChildren_Click()
DoCmd.OpenForm "MainData"
Forms!MainData.RecordSource = "RecordsAddressChildren"
End Sub

Private Sub RecordsAddress_Click()
DoCmd.OpenForm "MainData"
Forms!MainData.RecordSource = "RecordsAddress"
End Sub

Then there is a button on "MainData" Form that opens a Report. The
RecordSource for the Report needs to be the same as the one just chosen for
"MainData" Form.

How can I do this?

Thanks,
Paul
 
E

Elwin

Create a global variable in a module

Public strRS as String

Set the variable with your command button's Click() event

strRS = "MyQuery"

Apply the value with your report's OnOpen() event.

Me.RecordSource = strRS

Reset the variable with your report's OnClose() event.

strRS = ""
 
P

Paul Mars

Thanks,
P
Elwin said:
Create a global variable in a module

Public strRS as String

Set the variable with your command button's Click() event

strRS = "MyQuery"

Apply the value with your report's OnOpen() event.

Me.RecordSource = strRS

Reset the variable with your report's OnClose() event.

strRS = ""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top