Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    zero record return in select query (Access2000 or 97)

    I have a form based on select query. I want to have a MsgBox pop up instead of form opens when my select query return no record.
    Thanks <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: zero record return in select query (Access2000 or 97)

    In the on open event of the form you don't want to open, enter the following code :
    <pre>Private Sub Form_Open(Cancel As Integer)
    If Me.Recordset.RecordCount = 0 Then
    MsgBox "There is no data"
    Cancel = True
    End If
    End Sub</pre>

    Francois

  3. #3
    New Lounger
    Join Date
    May 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: zero record return in select query (Access2000 or 97)

    Thanks for your answer, but I opened this form from another form using VBA DoCmd method, which does not work with Cancel in the dialog box. Any idea?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: zero record return in select query (Access2000 or 97)

    In the code where you use the the docmd method to open the form, you have probably on error code. Something like
    <pre>Exit_Command279_Click:
    Exit Sub
    Err_Command279_Click:
    MsgBox Err.Description
    Resume Exit_Command279_Click
    End Sub</pre>

    Change it to
    <pre>Exit_Command279_Click:
    Exit Sub

    Err_Command279_Click:
    If Err.Number = 2501 Then
    Exit Sub
    End If
    MsgBox Err.Description
    Resume Exit_Command279_Click

    End Sub</pre>

    Francois

  5. #5
    New Lounger
    Join Date
    May 2002
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: zero record return in select query (Access2000 or 97)

    Thanks a lot!!!!!!!!!!!!!

Posting Permissions

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