Stop Form Opening

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

How do you stop a form from opening if it has no Data in it? The form
is based on a Query.
Thanks
DS
 
in message:
How do you stop a form from opening if it has no Data in it? The form
is based on a Query.

Use the form's open event to test the recordset returned.
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records to display at this time." _
, vbInformation, "No Records"
Cancel = True
End If
End Sub


You will of course need to trap for and ignore Error 2501
in the code routine that opens the form.
 
Jeff said:
in message:




Use the form's open event to test the recordset returned.
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records to display at this time." _
, vbInformation, "No Records"
Cancel = True
End If
End Sub


You will of course need to trap for and ignore Error 2501
in the code routine that opens the form.
Worked Great, I just Changed the Message Box and now I'm Happy!!!
Thanks
DS


Private Sub Form_Open(Cancel As Integer)
 
Back
Top