Cancel - on no data

J

Junior

Opening a report from a form -
When the report is closed i want to return to the form-
If the report has data the report close event will do this -
DoCmd.OpenForm "frmReports", acNormal, "", "", , acNormal

HOWEVER- if there is NO data - i also want the focus to return to the form
using the no data event - How do i return to the form if no data?

Private Sub Report_NoData(Cancel As Integer)
'(error handling ommitted)
MsgBox "There is no data to report." _
, vbOKOnly + vbInformation, "No Data Found"
Cancel = True
End Sub
 
K

Ken Snell

Either add the DoCmd step to the OnNoData code, or call the Close event code
for the report (assuming that the opening of the form is the only code step
in the OnClose procedure):

Private Sub Report_NoData(Cancel As Integer)
'(error handling ommitted)
MsgBox "There is no data to report." _
, vbOKOnly + vbInformation, "No Data Found"
Cancel = True
DoCmd.OpenForm "frmReports", acNormal, "", "", , acNormal
End Sub



Private Sub Report_NoData(Cancel As Integer)
'(error handling ommitted)
MsgBox "There is no data to report." _
, vbOKOnly + vbInformation, "No Data Found"
Cancel = True
Call Form_Close
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top