Application.DisplayAlerts

  • Thread starter Thread starter Jac Tremblay
  • Start date Start date
J

Jac Tremblay

Hi,
I cannot find how to prevent a message to be displayed when I try to insert
a record with the following command:
DoCmd.RunSQL strSql, UseTransaction:=False
Would anyone know some way to bypass the alert message?
Thanks
 
Try this

DoCmd.SetWarnings False
DoCmd.RunSQL strSql, UseTransaction:=False
DoCmd.SetWarnings True

but you need to ensure that warnings is set to "True" (in the error
handling) if there an error occures before you reach the " DoCmd.SetWarnings
True" line.


I prefer to use:

Currentdb.Execute strSQL,dbFailOnError


See help on the Execute method and the SetWarnings command.


HTH
 
Hi Steve,
This answers my question all right. I found out that I had myself used the
line:
Currentdb.Execute strSQL, dbFailOnError
in another project and never got any error. I will read about the difference
between the two in MSDN when I get the time (that will be soon).
In the mean time, I will use:
Currentdb.Execute strSQL, dbFailOnError
Thank you for your answer.
 
I prefer the Execute method.
It is faster to execute.
The reason it doesn't trigger the alert messages is that it does not go
through the Access User Interface. It goes directly to Jet. The Alerts are
in the UI. Now, the reason for the dbFailOnError is that since it doesn't go
through the UI, it will not throw an Access error, but the dbFailOnError
forces the error.

With a one record hit, you will hardly notice any difference; however, if
the SQL affects multiple records, you will notice the performance difference.

BTW, I don't agree with the previous poster's statment regarding the
SetWarnings statement. It really has nothing to do with error handling. I
keep my Display Alerts turned off all the time. I also have error handlers
in almost every procedure.
 
Hi Dave,
Your point is very interesing and I take good note of it. I will keep that
in mind for future development.
Thank you very much.
 
Back
Top