Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
Old 02-12-2003, 07:09 AM   #1
legendv
Senior Member
 
Join Date: Mar 2002
Location: Denison,TX,USA
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
legendv
suppress error messages

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

legendv is offline   Reply With Quote
Old 02-12-2003, 07:24 AM   #2
Autoeng
Why me?
 
Autoeng's Avatar
 
Join Date: Aug 2002
Location: Kentucky, USA
Posts: 1,302
Thanks: 0
Thanked 2 Times in 2 Posts
Autoeng
DoCmd.SetWarnings False

Be sure to turn the warnings back on with

DoCmd.SetWarnings True

Autoeng
Autoeng is offline   Reply With Quote
Old 02-12-2003, 07:40 AM   #3
Mile-O
Back once again...
 
Mile-O's Avatar
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,312
Thanks: 4
Thanked 116 Times in 107 Posts
Mile-O will become famous soon enough
Also, in code:

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

Mile-O is offline   Reply With Quote
Old 02-12-2003, 07:52 AM   #4
legendv
Senior Member
 
Join Date: Mar 2002
Location: Denison,TX,USA
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
legendv
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?
legendv is offline   Reply With Quote
Old 02-12-2003, 07:59 AM   #5
Autoeng
Why me?
 
Autoeng's Avatar
 
Join Date: Aug 2002
Location: Kentucky, USA
Posts: 1,302
Thanks: 0
Thanked 2 Times in 2 Posts
Autoeng
Put both lines in the same event. If you need to do in another event do so there as well.

Autoeng
Autoeng is offline   Reply With Quote
Old 02-12-2003, 08:17 AM   #6
legendv
Senior Member
 
Join Date: Mar 2002
Location: Denison,TX,USA
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
legendv
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 by legendv; 02-12-2003 at 08:27 AM.
legendv is offline   Reply With Quote
Old 02-14-2003, 03:11 PM   #7
Rakier
Registered User
 
Rakier's Avatar
 
Join Date: Mar 2002
Location: St. Louis, MO.
Posts: 75
Thanks: 0
Thanked 2 Times in 2 Posts
Rakier
I believe you will have to use error trapping to suppress that error.

Rakier is offline   Reply With Quote
Old 02-14-2003, 03:42 PM   #8
Rich
Guest
 
Posts: n/a
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
  Reply With Quote
Old 02-14-2003, 07:58 PM   #9
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 82 Times in 47 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
Cool

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
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 02-17-2003, 12:04 PM   #10
legendv
Senior Member
 
Join Date: Mar 2002
Location: Denison,TX,USA
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
legendv
I'm not worried about improper dates.
when an improper date is entered a microsoft msg occurs, I want to suppress the microsoft msg.
legendv is offline   Reply With Quote
Old 02-18-2003, 07:10 PM   #11
legendv
Senior Member
 
Join Date: Mar 2002
Location: Denison,TX,USA
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
legendv
Thanks all!
legendv is offline   Reply With Quote
Old 05-25-2003, 03:04 PM   #12
Bechert
Newly Registered User
 
Join Date: Apr 2003
Location: Monroe, WA, USA
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
Bechert
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
Bechert is offline   Reply With Quote
Old 05-27-2003, 04:42 AM   #13
ghudson
Newly Registered User
 
ghudson's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 6,199
Thanks: 1
Thanked 82 Times in 47 Posts
ghudson has a spectacular aura about ghudson has a spectacular aura about ghudson has a spectacular aura about
Wink

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
__________________
.................................................. ......
Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.

Well if it seems to be real, it's illusion...

I am using Access 2010 with Windows 7

The
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
function on this forum really does work.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

.................................................. ......
ghudson is offline   Reply With Quote
Old 11-30-2008, 01:15 PM   #14
fibayne
Newly Registered User
 
Join Date: Feb 2005
Location: Gibraltar
Posts: 235
Thanks: 18
Thanked 1 Time in 1 Post
fibayne is on a distinguished road
Re: suppress error messages

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
fibayne is offline   Reply With Quote
Old 11-30-2008, 03:26 PM   #15
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,421
Thanks: 51
Thanked 940 Times in 910 Posts
gemma-the-husky is a glorious beacon of light gemma-the-husky is a glorious beacon of light gemma-the-husky is a glorious beacon of light gemma-the-husky is a glorious beacon of light gemma-the-husky is a glorious beacon of light gemma-the-husky is a glorious beacon of light
Re: suppress error messages

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

gemma-the-husky is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 10:57 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World