SetWarnings Function 
Author Message
 SetWarnings Function

Hello:

I can't seem to get the SetWarnings function to work for me.  In the NoData
event of a report, I have the following code:

DoCmd.SetWarnings False
MsgBox "Sorry, but there is no data to report for this quarter."
DoCmd.CancelEvent
DoCmd.SetWarnings True

The message box appears as it should, but I keep getting the message box
after that:   The OpenReport action was cancelled

Any clues as to what I am doing wrong?  Thanks in advance for any help.

David



Sun, 02 Nov 2003 10:29:53 GMT  
 SetWarnings Function
SetWarnings relates to messages from action queries, not VBA errors.
Trap error 2501 in your code.

Example (assuming MyReport cancels its NoData event):
-------------------------------
Sub cmdReport_Click
On Error Goto Err_cmdReport_Click

  strWhere = "InvoiceDate Between #1/1/2001# And #3/31/2001#"
  DoCmd.OpenReport "MyReport", acViewPreview, strWhere

Exit_cmdReport_Click:
  Exit Sub

Err_cmdReport_Click:
  If Err.Number <> 2501 Then    'Ignore this error.
    MsgBox "Error " & Err.Number & " - " & Err.Description
  End If
  Resume Exit_cmdReport_Click
End Sub
-------------------------------

Quote:

> I can't seem to get the SetWarnings function to work for me.  In the NoData
> event of a report, I have the following code:

> DoCmd.SetWarnings False
> MsgBox "Sorry, but there is no data to report for this quarter."
> DoCmd.CancelEvent
> DoCmd.SetWarnings True

> The message box appears as it should, but I keep getting the message box
> after that:   The OpenReport action was cancelled

> Any clues as to what I am doing wrong?  Thanks in advance for any help.

> David

--
Perth, Western Australia
Tips for MS Access users at:
        http://odyssey.apana.org.au/~abrowne


Sun, 02 Nov 2003 10:55:13 GMT  
 SetWarnings Function
Try

Private Sub Report_NoData(Cancel As Integer)
  MsgBox "No Records found."
  Cancel = True
End Sub

HTH
Van T. Dinh



Quote:
> Hello:

> I can't seem to get the SetWarnings function to work for me.  In the
NoData
> event of a report, I have the following code:

> DoCmd.SetWarnings False
> MsgBox "Sorry, but there is no data to report for this quarter."
> DoCmd.CancelEvent
> DoCmd.SetWarnings True

> The message box appears as it should, but I keep getting the message box
> after that:   The OpenReport action was cancelled

> Any clues as to what I am doing wrong?  Thanks in advance for any help.

> David



Sun, 02 Nov 2003 16:00:40 GMT  
 SetWarnings Function
You probably need to trap for the error (2501) in the code opening the report.
The code below is a sample of how it is generally handled.

Private Sub cmdPreview_Click()

   On Error GoTo cmdPreview_Click_Error

   DoCmd.OpenReport "MyReport, acViewPreview

Exit Sub

cmdPreview_Click_Error:
    If Err.Number = 2501 Then
        'docmd.Restore
    Else
        MsgBox Err.Number & " - " & Err.Description
    End If
End Sub

Quote:

> Hello:

> I can't seem to get the SetWarnings function to work for me.  In the NoData
> event of a report, I have the following code:

> DoCmd.SetWarnings False
> MsgBox "Sorry, but there is no data to report for this quarter."
> DoCmd.CancelEvent
> DoCmd.SetWarnings True

> The message box appears as it should, but I keep getting the message box
> after that:   The OpenReport action was cancelled

> Any clues as to what I am doing wrong?  Thanks in advance for any help.

> David



Sun, 02 Nov 2003 20:16:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. SetWarnings Function

2. SetWarnings goofiness ?

3. setwarnings

4. DoCmd.SetWarnings False

5. SetWarnings is Making Me go Bat Guano!

6. Setwarnings/DisplayAlerts equivalent

7. Running Excel function from Access function/macro

8. findlast function is not functioning?

9. new type of aggregate function (product function)

10. functions calling other functions

11. Function based on Function

12. Calling Function in CBF from Toolbar via a Public Function

 

 
Powered by phpBB® Forum Software