• DCount or NoData ?? (Access 97)

    Author
    Topic
    #360258

    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

    England blank

    Viewing 1 reply thread
    Author
    Replies
    • #542094

      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).

      chatter

    • #542095

      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

      • #542140

        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.

    Viewing 1 reply thread
    Reply To: DCount or NoData ?? (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: