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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zero records prevent open 1

Status
Not open for further replies.
Apr 23, 2002
39
US
A have a switchboard that opens a form. The data source for the form is a query that can return ZERO records. How can I prevent the form from opening if there are NO records, or at least display a message, then close the form.
 
How about:

Code:
Private Sub Form_Open(Cancel As Integer)
Dim strRecError

If Me.RecordSource <> "" Then
    If Me.Recordset.RecordCount = 0 Then
        strRecError = "No Records. "
    End If
Else
    strRecError = "No recordset. "
End If
If strRecError <> "" Then
    If MsgBox(strRecError & "Continue?", vbYesNo) = vbNo Then
        Cancel = True
    End If
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top