Supress Warning Messages

Will04

Registered User.
Local time
Today, 12:57
Joined
May 29, 2006
Messages
62
Hi everyone,

I have placed the following Code in the OnOpen event of a form to check if any records exists. If there are no records, then a message is displayed.

Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.SetWarnings False
If Me.RecordsetClone.RecordCount = 0 Then
  MsgBox "Sorry!!! No Matching Record found!"
  Cancel = True
DoCmd.SetWarnings True

End If

This is working fine, except that I'm getting an additional messsage which states "The OpenForm action was canceled"

How do I stop this message from being displayed??

I've tried to use SetWarnings but It's not working..


Any suggestions??


Thanks

Will
 
You can add an error handler and test for error 8301, then just add "Resume next"
 
Hi Jklo,

I tried the following, but I'm still getting the message being displayed.

Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Error

If Me.RecordsetClone.RecordCount = 0 Then
  MsgBox "Sorry!!! No Matching Record found!"
  Cancel = True
End If
    
Form_Open_Exit:
    Exit Sub
        
Form_Open_Error:
    If Err.Number = 8301 Then
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Form_Open_Exit
    End If

End Sub

Any idea what I'm doing wrong?


Thanks

Will
 
8301 comes up as no error in my reference list, which basically means Micro$oft hasn't assigned it yet. Try substituting

If Err.Number = 2501 Then

and see if that isn't it.
 
Yes, 2501 is the correct one to check for. Plus, if you are cancelling the opening of the form, you need to set the error handler, checking for err.Number=2501 in the event that opens the form, not the form's open event.
 
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Sorry!!! No Matching Record found!"
DoCmd.Close acForm, Me.Name
 
Hi Rich,
I tried your suggestion and it worked beautifully.. Thanks so much.

Missingling,Bob :
I changed the Err# to 2501, but it still didn't work.
The situation is that I have a command button which links to a form which is based on a query.
When I click on the button, the query requests a file number and then opens the form with that specific record.
Right now the error checking is done on the form open event - DOES NOT WORK.

Where do you suggest that I place the error checking?

In the meantime Rich's suggestion is working for me..


Thanks for all the help

Appreciated

Will
 

Users who are viewing this thread

Back
Top Bottom