Access & warning trap

V

Vuillermet Jacques

With VBA, we can trap error with :

On Error ...

About the warnings, we can disabled them with :

DoCmd.SetWarnings False

But how to trap the warnings ?
On warning, I want to run specific code instead of showing the in-built
message box to the user.

Thanks.

Jacques.
 
S

solex

Jacques,

In the code where you want to trap the warnings issue the DoCmd.SetWarning
to True after the code is finished executing reset the warnings to False.

Regards,
Dan
 
T

Tim Ferguson

DoCmd.SetWarnings False

But how to trap the warnings ?
On warning, I want to run specific code instead of showing the in-built
message box to the user.

Depends on what you are doing at the time. Many of the macro commands have
proper database methods that you can call; for example, instead of

DoCmd.RunSQL

use

db.Execute strCommand, dbFailOnError

and get a normal vb Error. Similarly, force-saving a form can be achieved
with

Me.Dirty = False

rather than DoCmd.RunCommand and so on. If it's a database command, you can
do it with one of the ADO or DAO methods; for most of the GUI stuff you can
call the Forms() or Reports() methods or properties etc. I very rarely use
the DoCmd object; and when I do, I recognise it as a warning that I am
probably going the wrong way about something.

The biggest exception is DoCmd.OpenForm and .OpenReport, and that is
because DAO does not have a good way of manipulating the Forms() and
Reports() collections. The desired syntax would be something like

Forms.Add "frmPatientContacts", dbFormHidden
With Forms("frmPatientContacts")
.PatientID = 30458
.DateFrom = #2004-01-01#
.Requery
.Visible = True

End With

but we can't do that, so there.


All the best


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top