Dynamic RecordSource for Report

  • Thread starter Thread starter Michael
  • Start date Start date
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
 
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
 
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
 
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
 
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.
 
Back
Top