Hello:
What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on the form and then via the cmdbutton the report opens in preview mode. I want to stop it from executing if the query is empty. I thought I could do this by checking the record count by the following code but I error out with the following message:
[code=text]
Too few parameters. Expected <number>. (Error 3061)
This parameter query requires the specified number of parameters, which you did not supply. Provide the expected number of parameters, and run the query again.
[/code]
Here is my code:
[code=vb]
Private Sub cmdRptSummary_C lick()
'Checks to see if any of the controls are null
If Nz([CboYear], 0) = 0 Or Nz([CboMonth], 0) = 0 _
Or Nz([cboWeek], 0) = 0 Then
If Nz([CboYear], 0) = 0 Then MsgBox "Please select the Forecast Year from the" & _
" drop down menu", 64, "Select Forecast Year"
If Nz([CboMonth], 0) = 0 Then MsgBox "Please select the Forecast Month from the" & _
" drop down menu", 64, "Select Forecast Month"
If Nz([cboWeek], 0) = 0 Then MsgBox "Please select the Forecast Week from the" & _
" drop down menu", 64, "Select Forecast Week"
Else
'If no null values then check to see if there is data to report on
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenR ecordset("QryFo recastSummary")
If rst.BOF And rst.EOF Then 'If none, then end process and send out MsgBox
MsgBox "Given your selections, there are no records to delete and reload.", 64, "No Records Match"
Else
'If there is data, open the Forecast Summary Report
DoCmd.OpenRepor t "SumReport" , acViewPreview
End If
End If
End Sub
[/code]
The error focus is on the following line:
[Code=vb]
Set rst = CurrentDb.OpenR ecordset("QryFo recastSummary")
[/Code]
I never set a openrecordset to a query before so I am thinking that that is where my problem is.... I now the query works when I test it without the command button...
Any ideas?
Thanks,
Keith.
What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on the form and then via the cmdbutton the report opens in preview mode. I want to stop it from executing if the query is empty. I thought I could do this by checking the record count by the following code but I error out with the following message:
[code=text]
Too few parameters. Expected <number>. (Error 3061)
This parameter query requires the specified number of parameters, which you did not supply. Provide the expected number of parameters, and run the query again.
[/code]
Here is my code:
[code=vb]
Private Sub cmdRptSummary_C lick()
'Checks to see if any of the controls are null
If Nz([CboYear], 0) = 0 Or Nz([CboMonth], 0) = 0 _
Or Nz([cboWeek], 0) = 0 Then
If Nz([CboYear], 0) = 0 Then MsgBox "Please select the Forecast Year from the" & _
" drop down menu", 64, "Select Forecast Year"
If Nz([CboMonth], 0) = 0 Then MsgBox "Please select the Forecast Month from the" & _
" drop down menu", 64, "Select Forecast Month"
If Nz([cboWeek], 0) = 0 Then MsgBox "Please select the Forecast Week from the" & _
" drop down menu", 64, "Select Forecast Week"
Else
'If no null values then check to see if there is data to report on
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenR ecordset("QryFo recastSummary")
If rst.BOF And rst.EOF Then 'If none, then end process and send out MsgBox
MsgBox "Given your selections, there are no records to delete and reload.", 64, "No Records Match"
Else
'If there is data, open the Forecast Summary Report
DoCmd.OpenRepor t "SumReport" , acViewPreview
End If
End If
End Sub
[/code]
The error focus is on the following line:
[Code=vb]
Set rst = CurrentDb.OpenR ecordset("QryFo recastSummary")
[/Code]
I never set a openrecordset to a query before so I am thinking that that is where my problem is.... I now the query works when I test it without the command button...
Any ideas?
Thanks,
Keith.
Comment