Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002

    Unanswered: Closing a form when Query returns zero records?

    If you have a form who's record set is based on a criteria that is prompted for by the query, and the query result is zero records,
    what code in the onOpen property of the form will catch the zero records and give the user a custom error message and automatically close the form?

    What I'm trying to do is from a switchboard, a form is called that's record set is based on a query. The query has a [prompt] in the
    criteria, and this brings up a dialog asking for a student id when the form is opened. If the user enters an id that is not in the table, the resultant record set is zero records and the form opens blank.

    I want to be able to determine the recordset is blank or null or zero, and
    automatically put up a error message "student Id number not found" and close the form.

    Any help on the code for this would be appreciated

    Dan Roth

  2. #2
    Join Date
    Nov 2001
    Try this:

    Private Sub Form_Open(Cancel As Integer)
    If Me.Recordset.RecordCount = 0 Then
    msgbox "Student ID not Found."
    Cancel = True
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts