Dynamic RecordSource for Report

M

Michael

Hi Folks - Report A's recordsource is Query A. How can I use a different
query for Report A at runtime? Thanks.

Michael
 
F

fredg

Hi Folks - Report A's recordsource is Query A. How can I use a different
query for Report A at runtime? Thanks.

Michael

You can simply change the report's record source in the report's Open
event.

What determines which query to use?

If [SomeCriteria] = something Then
Me.RecordSource = "QueryA"
Else
Me.Recordsource = "QueryB"
End If
 
F

fredg

Hi Folks - Report A's recordsource is Query A. How can I use a different
query for Report A at runtime? Thanks.

Michael

You can simply change the report's record source in the report's Open
event.

What determines which query to use?

If [SomeCriteria] = something Then
Me.RecordSource = "QueryA"
Else
Me.Recordsource = "QueryB"
End If
 
M

magick

hi - trying to change the record source based on a form control with the
following code, which is not working (doesn't like the if statement) what am
i doing wrong? thanks so much.

Private Sub Report_Open(Cancel As Integer)
If Forms!Query!txtFundNode Is Null Then
Report.RecordSource = "BuildLgr_Node5"
Else
Report.RecordSource = "BuildLgr_Node5_Fund"
End If

End Sub


fredg said:
Hi Folks - Report A's recordsource is Query A. How can I use a different
query for Report A at runtime? Thanks.

Michael

You can simply change the report's record source in the report's Open
event.

What determines which query to use?

If [SomeCriteria] = something Then
Me.RecordSource = "QueryA"
Else
Me.Recordsource = "QueryB"
End If
 
F

fredg

hi - trying to change the record source based on a form control with the
following code, which is not working (doesn't like the if statement) what am
i doing wrong? thanks so much.

Private Sub Report_Open(Cancel As Integer)
If Forms!Query!txtFundNode Is Null Then
Report.RecordSource = "BuildLgr_Node5"
Else
Report.RecordSource = "BuildLgr_Node5_Fund"
End If

End Sub

fredg said:
Hi Folks - Report A's recordsource is Query A. How can I use a different
query for Report A at runtime? Thanks.

Michael

You can simply change the report's record source in the report's Open
event.

What determines which query to use?

If [SomeCriteria] = something Then
Me.RecordSource = "QueryA"
Else
Me.Recordsource = "QueryB"
End If

Try it this way:

If IsNull(Forms!Query!txtFundNode) Then
Me.RecordSource = "BuildLgr_Node5"
Else
Me.ReccordSource = "BuildLgr_Node5_Fund"
End If

The form must be open when the report is run.
 

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