Trapping Warning Messages, NOT Error Messages 
Author Message
 Trapping Warning Messages, NOT Error Messages

I am running Access 97.
I am trying to trap some warning messages that occur when
I run Append Queries in code, I know I can disable them
with docmd.setwarnings = false, but I would like to trap
them so I can count the number of times they occur.
Basically I am appending records some of which will not
successfully append due to key violations which is fine
(this is the warning message to trap), I just want to
count the number of successful appends. I am appending one
row at a time with a For Next loop. These warning messages
don't seem to have error numbers like regular run time
errors so I was wondering if any one knew of a way to trap
them. Any help would be appreciated.

Brian C. Smith
St. Louis, MO USA



Mon, 12 Dec 2005 00:29:27 GMT  
 Trapping Warning Messages, NOT Error Messages


Quote:
> I am trying to trap some warning messages that occur when
> I run Append Queries in code, I know I can disable them
> with docmd.setwarnings = false, but I would like to trap
> them so I can count the number of times they occur.

don't use DoCmd.RunSQL, use

 db.Execute strMySQLStatement, dbFailOnError

and use On Error to catch anything that goes wrong.

Hope that helps

Tim F



Mon, 12 Dec 2005 02:04:44 GMT  
 Trapping Warning Messages, NOT Error Messages
If you know the error number (displayed in msgbox, can't reproduce it now) and you have errorhandler trapping this specific error,
you can put a counter there, which is returned on exiting function. Also, put a resume next there, cause you want code to continue
after error occurred\is trapped.

Jacques
www.troisj.com



Quote:
> I am trying to trap some warning messages that occur when
> I run Append Queries in code, I know I can disable them
> with docmd.setwarnings = false, but I would like to trap
> them so I can count the number of times they occur.

don't use DoCmd.RunSQL, use

 db.Execute strMySQLStatement, dbFailOnError

and use On Error to catch anything that goes wrong.

Hope that helps

Tim F



Mon, 12 Dec 2005 02:48:34 GMT  
 Trapping Warning Messages, NOT Error Messages

Quote:
> I am running Access 97.
> I am trying to trap some warning messages that occur when
> I run Append Queries in code, I know I can disable them
> with docmd.setwarnings = false, but I would like to trap
> them so I can count the number of times they occur.
> Basically I am appending records some of which will not
> successfully append due to key violations which is fine
> (this is the warning message to trap), I just want to
> count the number of successful appends. I am appending one
> row at a time with a For Next loop. These warning messages
> don't seem to have error numbers like regular run time
> errors so I was wondering if any one knew of a way to trap
> them. Any help would be appreciated.

Use the db.Execute method, as suggested by Tim Ferguson, but after each
operation, check the value of db.RecordsAffected, like this:

    Dim db As DAO.Database
    Dim strInsertSQL As String
    Dim lngTotalInserted As Long

    Set db = CurrentDb

    ' ...
    ' ... build SQL statement in strInsertSQL ...

    db.Execute strInsertSQL, dbFailOnError
    lngTotalInserted = lngTotalInserted + db.RecordsAffected

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)



Mon, 12 Dec 2005 02:57:38 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Get a warning message when programatically forward message

2. Warning message on document that Macros are not running

3. trapping info in an error message

4. Trap and Replace Error Messages

5. how to trap ADO update error instead of a message box

6. How do I trap spelling error message fr embedded word OLE object

7. Connection not Open + Server has not yet been opened error messages

8. Messaging Services and their use (not email messaging)

9. Why does Message Box does not display complete Message

10. The infamous Message Filter error - Illegal to call out while ins ide Message Filter (-2147418107)

11. Suppressing a warning message

12. Warning message when exiting database

 

 
Powered by phpBB® Forum Software