K
Ken Ivins
I have run into this before and thought it was time to learn the right way.
I have one report and many queries. The queries all have the same fields,
just different sorting based on the input from the user. In the past I
would just copy and paste the report and change its record source to the new
query but I thought I could change the record source with code.
On a form I created two buttons (see code below). One for one query and the
other for the other. In both cases I got a report with the data for the
query in the recordsource field. If I leave the recordsource field on the
report blank I get no data.
Do I need to change my code or something in the report? Access help makes it
look easy but I am missing something.
Thanks,
Ken
Private Sub cmdAllCountiesAllIssues_Click()
On Error GoTo Err_cmdAllCountiesAllIssues_Click
Dim stDocName As String
Dim stQryName As String
stDocName = "rptCountyIssues"
stQryName = "qryCountyByIssue-AllCountyAllIssuesRpt"
DoCmd.OpenReport stDocName, acPreview, stQryName
Exit_cmdAllCountiesAllIssues_Click:
Exit Sub
Err_cmdAllCountiesAllIssues_Click:
MsgBox Err.Description
Resume Exit_cmdAllCountiesAllIssues_Click
End Sub
Private Sub cmdAllCountiesSelectedIssues_Click()
On Error GoTo Err_cmdAllCountiesSelectedIssues_Click
Dim stDocName As String
Dim stQryName As String
stDocName = "rptCountyIssues"
stQryName = "qryCountyByIssue-AllCountySelectIssuesRpt"
DoCmd.OpenReport stDocName, acPreview, stQryName
Exit_cmdAllCountiesSelectedIssues_Click:
Exit Sub
Err_cmdAllCountiesSelectedIssues_Click:
MsgBox Err.Description
Resume Exit_cmdAllCountiesSelectedIssues_Click
End Sub
I have one report and many queries. The queries all have the same fields,
just different sorting based on the input from the user. In the past I
would just copy and paste the report and change its record source to the new
query but I thought I could change the record source with code.
On a form I created two buttons (see code below). One for one query and the
other for the other. In both cases I got a report with the data for the
query in the recordsource field. If I leave the recordsource field on the
report blank I get no data.
Do I need to change my code or something in the report? Access help makes it
look easy but I am missing something.
Thanks,
Ken
Private Sub cmdAllCountiesAllIssues_Click()
On Error GoTo Err_cmdAllCountiesAllIssues_Click
Dim stDocName As String
Dim stQryName As String
stDocName = "rptCountyIssues"
stQryName = "qryCountyByIssue-AllCountyAllIssuesRpt"
DoCmd.OpenReport stDocName, acPreview, stQryName
Exit_cmdAllCountiesAllIssues_Click:
Exit Sub
Err_cmdAllCountiesAllIssues_Click:
MsgBox Err.Description
Resume Exit_cmdAllCountiesAllIssues_Click
End Sub
Private Sub cmdAllCountiesSelectedIssues_Click()
On Error GoTo Err_cmdAllCountiesSelectedIssues_Click
Dim stDocName As String
Dim stQryName As String
stDocName = "rptCountyIssues"
stQryName = "qryCountyByIssue-AllCountySelectIssuesRpt"
DoCmd.OpenReport stDocName, acPreview, stQryName
Exit_cmdAllCountiesSelectedIssues_Click:
Exit Sub
Err_cmdAllCountiesSelectedIssues_Click:
MsgBox Err.Description
Resume Exit_cmdAllCountiesSelectedIssues_Click
End Sub