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!

Need code to return to form on no data

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
Hi, I wasn't sure whether this is a form issue or a report issue so hope this is the correct forum.

I use a form to list a lot of my reports and then when I want to preview a report I have a button with the following code

Code:
Private Sub CmdPreviewReport_Click()
On Error Resume Next
    Select Case Me.ReportName
        Case "rpt25-NutrientBalance"
            DoCmd.OpenForm "frmSlt4RptNutrientBalance"
            If Err = 2501 Then Err.Clear
        Case Else
            DoCmd.OpenReport Me.[ReportName], acViewPreview
    End Select
    DoCmd.Close acForm, "frmPrintRpts"
    If Err = 2501 Then Err.Clear
End Sub

In the on NoData event of the reports I have
Code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are currently no records available for this report."
    Cancel = True
End Sub

Everything works fine except that when there is no data and the OK is clicked then I would like to return to the form frmPrintRpts and I am not sure how to do that. Can anyone tell me how to do this please.

Thank you

 
I would think you need to count the control source set. If it is 0, then issue the message.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
For reference I solved this issue by moving the

Code:
DoCmd.Close acForm, "frmPrintRpts"

from the preview report button to the onload of the report so the Print Reports form now only closes when the report loads.
 
If you are opening a report, you can use the on no data property. I usually issue a message when closing, to let the user know that there was no data for their provided criteria.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top