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

How to Refer to A Report That is Not Currently Open

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
I need to set the Recordsource property of a report when a command button is clicked.

Here's what I did so far.

1. Tried to refer to the report in the code before opening the report itself. Here's the Code -->

Private Sub cmdPrint_Click()

Dim qry As QueryDef
Dim db As Database
Dim rpt As Report

Set db = CurrentDb
Set qry = db.QueryDefs("qryReportBase")
Set rpt = Reports("Segments")
rpt.RecordSource = qry.SQL

DoCmd.OpenReport "Segments", acPreview

End Sub

RESULT: I get an error saying that I am referring to a report that doesn't exist. I double-checked spelling and everything, and the report exists.

2. So I moved all of the report stuff after the DoCmd.OpenReport Statement. Like this -->

Private Sub cmdPrint_Click()
Dim sSQL As String
Dim qry As QueryDef
Dim db As Database
Dim rpt As Report

Set db = CurrentDb
Set qry = db.QueryDefs("qryReportBase")

DoCmd.OpenReport "Segments", acPreview
Set rpt = Reports("Segments")
rpt.RecordSource = qry.SQL

End Sub

RESULT: Now the report is found because it's open, but now I get an error saying that I can't set the recordsource property after printing has started.

So how do I refer to this thing and set the recordsource property before the report opens?

Help appreciated,
Clay Simmons
 
Never mind. Just moved the code to the OnOpen event of the report. Silly me. Should have thought of that one earlier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top