Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No data for Form to display (Access 2003)

    I have a situation where one form builds the criteria for a form.

    What I want to do is display a message saying that no data was found from their selected criteria.
    When they click on the message I want the result form to close and reposition back on the search form.

    I am able to display the message when I get the no data condition but can't figure out how to close the form.
    I've tried the docmd.close after the check but Access says I can't do that here and I can't find a nodata event.

    Can anyone tell me where I can place the close command to force the form to close.

    Here is my current code for checking for data.

    Option Compare Database
    Dim noData As Boolean

    Private Sub Form_Activate()
    Dim rs As DAO.Recordset

    Set rs = Me.Recordset

    noData = False
    If rs.EOF Then
    MsgBox "No Bills found for your search." & vbNewLine _
    & "Please enter new criteria."
    noData = True
    <font color=red>Here is where I would like to close this form</font color=red>
    Else
    DoCmd.OpenForm "look up2 for 2003", , , , , acHidden
    End If

    End Sub

    Thank you
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: No data for Form to display (Access 2003)

    This can all be done in Open Event of the form you want to open. It would look like this (assuming there is no other code there already):

    Private Sub Form_Open (Cancel as Integer)
    if Me.recordsourceClone.RecordCount=0 then
    MsgBox "No Records Found!",vbcritical
    Cancel = True
    Exit sub
    End If
    End Sub
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: No data for Form to display (Access 2003)

    Thanks Mark.

    Just a follow-up. Is there a way to suppress the message "The OpenFormaction was canceled."

    I've tried the docmd.setwarning (false) but it still displays.

    Edited for spelling error.
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: No data for Form to display (Access 2003)

    In your calling form, have your error handler check for then just do a "Resume Next" if the err.number = 2501.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: No data for Form to display (Access 2003)

    Thanks Mark.
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

Posting Permissions

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