By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

SETTING DIFFERENT RECORDSOURCES FOR ONE REPORT

P: n/a
Hi:

I need to set the RecordSource of a single report to a different query
each time the report is run.

I'd like to do something in VBA like:

If Me.PK_Rules = 1 Then

DoCmd.OpenQuery "Find1", acViewNormal

Dim strRpt As String
strRpt = "rptSnapshotPrint"

strRpt.RecordSource = "Find1"
strRpt.Visible = True

DoCmd.OpenReport strRpt, acViewPreview

If Me.PK_Rules = 2 Then

DoCmd.OpenQuery "Find2", acViewNormal

Dim strRpt As String
strRpt = "rptSnapshotPrint"

strRpt.RecordSource = "Find2"
strRpt.Visible = True

DoCmd.OpenReport strRpt, acViewPreview

End If
===

Is this possible? The syntax above is not correct -- can anyone help?
I've tried to set the "Where" clause of the DoCmd.OpenReport too, but
haven't had any luck.

Thanks!

amy
==

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
am*******@verizon.net wrote:
I need to set the RecordSource of a single report to a different query
each time the report is run.

I'd like to do something in VBA like:
If Me.PK_Rules = 1 Then
DoCmd.OpenQuery "Find1", acViewNormal
Dim strRpt As String
strRpt = "rptSnapshotPrint"
strRpt.RecordSource = "Find1"
strRpt.Visible = True [snip] Is this possible? The syntax above is not correct -- can anyone help?
I've tried to set the "Where" clause of the DoCmd.OpenReport too, but
haven't had any luck.


You do not need to "Open" a query for a report to use it, and the place to
dynamically set the RecordSource for the Report is with code in the Report's
Open event, not from some other module.

Select Case Forms!NameOfYourForm!PK_Rules
Case 1
Me.RecordSource = "Find1"
Case 2
Me.RecordSource = "Find2"
End Select

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

P: n/a
If all you are doing is filtering a single table/rowsource, then just
use the WHERE clause of the open event... Kind of hard to imagine why
you'd have a zillion queries that do basically the same thing to do
this...

Nov 13 '05 #3

P: n/a

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:36*************@individual.net...
You do not need to "Open" a query for a report to use it, and the place to
dynamically set the RecordSource for the Report is with code in the
Report's
Open event, not from some other module.

Select Case Forms!NameOfYourForm!PK_Rules
Case 1
Me.RecordSource = "Find1"
Case 2
Me.RecordSource = "Find2"
End Select


Select Case PK_Rules
Case 1
Me.RecordSource = "Find1"
Case 2
Me.RecordSource = "Find2"
End Select

***Sherwood Wang MVP***
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.