Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Aug 2001
    Location
    Toronto, Ontario, Canada
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DCount or NoData ?? (Access 97)

    Okee-Dokee :

    I am experimenting with different ways to stop a report from Previewing if there is NoData. I tried the NoData event for the report and added my MsgBox "No Data" and Cancel = True. This works fine if I access the report directly BUT when I access the report through the OnClick Event of a button in a form it displays my MsgBox AND the system generated one about Canceling an event, etc, etc. No matter what I do, I cannot stop that from showing.

    Next, I tried adding DCount to the OnClick Event of the button so I could stop it even before I got to the report (see Code below). This works fine, but I have noticed that it does increase the wait time for the user by a few seconds or so.

    I guess my questions would be : Any ideas why I cannot stop the system generated message when I go through a form to view a report. Or, any other ideas at the OnClick Event of the Preview button that may be a bit quicker than DCount ????

    Any suggestions would be warmly welcomed. TIA


    Private Sub cmdPreview_Click()
    On Error GoTo Err_cmdPreview_Click

    DoCmd.Hourglass True

    *Checks to see if there is any data matching the criteria *
    If DCount("*", "qryReport02_ProjectActivityLog") < 1 Then
    DoCmd.Hourglass False
    MsgBox "No matches found. @Please try again.@"
    Exit Sub
    End If

    * Closes Report Selection Form *
    DoCmd.Close
    * Opens Report *
    DoCmd.OpenReport "rptProject-Activity-Log", acPreview

    DoCmd.Hourglass False

    Exit_cmdPreview_Click:
    Exit Sub

    Err_cmdPreview_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_cmdPreview_Click

    End Sub

    <img src=/S/flags/England.gif border=0 alt=England width=30 height=18> <img src=/S/blank.gif border=0 alt=blank width=15 height=15>

  2. #2
    Star Lounger
    Join Date
    Sep 2001
    Location
    SC, USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DCount or NoData ?? (Access 97)

    Go back to your original "On click" code (not the DCount code), and try this before you open the report:

    DoCmd.SetWarnings False

    Then add this after opening the report:

    DoCmd.SetWarnings True

    This should stop the systen generated message. (Always set warnings back to true, to catch any other errors that may occur).

    <img src=/S/chatter.gif border=0 alt=chatter width=38 height=16>

  3. #3
    Lounger
    Join Date
    Aug 2001
    Location
    Toronto, Ontario, Canada
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DCount or NoData ?? (Access 97)

    Thanks. Tried that but still no luck unfortunately. This is the message I get exactly :

    "The OpenReport Action was Cancelled. You used a method of the DoCmd object to carry out an action in Visual Basic (I am not!), but then clicked Cancel in a dialog box (did 1?). For example, you used the Close Method to close a changed form, then clicked Cancel in the Dialog box that asks if you want to save the changes you made to the form."

    This is my OnNo Data code :

    Private Sub Report_NoData(Cancel As Integer)

    MsgBox "No Matches found. @Please try again@."
    Cancel = True

    End Sub


    and this is my onclick code:

    Private Sub cmdPreview_Click()
    On Error GoTo Err_cmdPreview_Click

    DoCmd.SetWarnings False

    DoCmd.Close ' *** Close the report selection form ***
    DoCmd.OpenReport "rptProject-Activity-Log", acPreview

    DoCmd.SetWarnings True

    Exit_cmdPreview_Click:
    Exit Sub

    Err_cmdPreview_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_cmdPreview_Click

    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: DCount or NoData ?? (Access 97)

    This is a very common problem and has been addressed many times here in the Lounge. The quick answer is to trap for the 2501 error in your commandbutton routine and then simply ignore it. Try 2501 for other threads on this problem.
    Charlotte

Posting Permissions

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