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"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set rpt = Reports("Segments"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
DoCmd.OpenReport "Segments", acPreview
Set rpt = Reports("Segments"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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
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