suppress error messages (1 Viewer)

legendv

Registered User.
Local time
Today, 09:10
Joined
Mar 18, 2002
Messages
99
How do you suppress Microsoft Access error messages?
For instance, when user enters date format incorrectly I would like my own msgbox to appear instead of access. But I don't know how to suppress MS A2K's error msg.

Any suggestions?

Thanks
 

Autoeng

Why me?
Local time
Today, 04:10
Joined
Aug 13, 2002
Messages
1,302
DoCmd.SetWarnings False

Be sure to turn the warnings back on with

DoCmd.SetWarnings True

Autoeng
 

Mile-O

Back once again...
Local time
Today, 09:10
Joined
Dec 10, 2002
Messages
11,316
Also, in code:

Use error trapping within your procedures to ensure that you capture and customise other error messages.
 

legendv

Registered User.
Local time
Today, 09:10
Joined
Mar 18, 2002
Messages
99
What I did:

On Enter,
DoCmd.SetWarnings False

On Lost Focus,
DoCmd.SetWarnings True

This didn't work, I'm I using it in the wrong area. (Obviously my logic is off ;-)

Where should it go?
 

Autoeng

Why me?
Local time
Today, 04:10
Joined
Aug 13, 2002
Messages
1,302
Put both lines in the same event. If you need to do in another event do so there as well.

Autoeng
 

legendv

Registered User.
Local time
Today, 09:10
Joined
Mar 18, 2002
Messages
99
It didn't work - (possibly I'm doing something wrong)

ok, there is a formated date field that works great when entered correctly. But if you enter 000000, you of course get an error message. I want to suppress the MS A2K error message and replace it with my own message box.

I placed:
DoCmd.SetWarnings False
DoCmd.SetWarnings True

in the same event settings below
AfterUpdate
BeforeUpdate
Change
Enter
Exit
GotFocus
LostFocus

no luck, still getting MS A2K error msg?!

Am I not doing it correctly?
 
Last edited:

Rakier

Registered User.
Local time
Today, 09:10
Joined
Mar 21, 2002
Messages
75
I believe you will have to use error trapping to suppress that error.
 
R

Rich

Guest
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2113 Then

MsgBox "Invalid entry"
Me.Undo

Response = acDataErrContinue


Else
'If another error is applied then show the standard error message
Response = acDataErrDisplay
End If
End Sub
 

ghudson

Registered User.
Local time
Today, 04:10
Joined
Jun 8, 2002
Messages
6,195
As a rule, all functions and subs should have proper error trapping.

You have a few options since you are worried about invalid dates...

You could create an input mask to force the user to correctly key in a date. Try this as an input mask for your date field...
00\ /\ 00\ /\ 0000;0;0_

You could use IsDate to ensure the date keyed is a valid date. Check the help files for the IsDate function for more options and examples.

HTH
 

legendv

Registered User.
Local time
Today, 09:10
Joined
Mar 18, 2002
Messages
99
I'm not worried about improper dates.
when an improper date is entered a microsoft msg occurs, I want to suppress the microsoft msg.
 

Bechert

Registered User.
Local time
Today, 09:10
Joined
Apr 11, 2003
Messages
59
Legendv, I am looking for a way to suppress the MS Access error messages and replace them with my own, user friendly messages. Did you ever find a way to do this?

Thanks,
Bill
 

ghudson

Registered User.
Local time
Today, 04:10
Joined
Jun 8, 2002
Messages
6,195
You need to trap for the specific error number. Below is an example of trapping
for error number's 2046 & 2501 for my custom delete button...
Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.RunCommand acCmdDeleteRecord
    End If
    
Exit_bDelete_Click:
    Exit Sub
    
Err_bDelete_Click:
    If Err = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        Beep
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
Also, you should use the IsDate Function if you want to test if a date keyed is a valid date.
Check the help files for "IsDate" if you need more info and an example.

HTH
 

fibayne

Registered User.
Local time
Today, 10:10
Joined
Feb 6, 2005
Messages
236
ghudson....brilliant thanks spent all day looking through threads to suppress error messages, found yours and 2 mins later all done ...big thanks cheers Fi
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:10
Joined
Sep 12, 2006
Messages
15,634
you need to use some sort of error handling to protect any operation unless you are absolutely sure it cant fail.

the setwarnings true and false are really used to suppress output from queries

eg, when you manually execute an update query, you get the "you are about to update x messages", and more importantly, your users can stop exection by saying "No"

by surrounding the query with the setwarnings code you

a) suppress the messages and
b) prevent users being able to crash out of importnat processes

so you get

docmd.setwarnings false
docmd.openquery "my update query"
docmd.setwarnings true

now the only problem is, is that you are also suppressing warning messages - so say this is an insert query, and some inserts fail., then you dont get informed that this has happened.

If this is important you can use instead

on error goto fail:
currentdb.execute "my update query" ,dbfailonerror

msgbox("Completed")

'prevent code falling into the error handler
exit sub

fail:
error handling here

.... but now, you have ot add your own error handling
docmd.setwarnings true

-------
finally note that in a error handler you HAVE to close it with a resume statement - dont just goto, as you cannot set another error trap until you resume from the first
 

Users who are viewing this thread

Top Bottom