Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of the default error message.

Status
Not open for further replies.

webwevers

Programmer
May 10, 2002
15
0
0
US
Hi, I would like to get rid of the default error message when I run a append query. I now get a 3059 error message telling me I can't append duplicate values. I do need to trap for duplicate values, I just would like a better error message that the users will understand. I am able to get my error message to come up but only after the default one. I just need to stop the default one. Maybe this is not possible. Thanks.
 
How are you executing the append query? From code or from a macro?

The best way would be to execute it from code, and use a querydef object. This method doesn't present any error messages to the user unless the query itself has a syntax error.

You would do something like this:

Code:
Dim db as DAO.Database
Dim qdf as DAO.Querydef

Set db = Currentdb()
Set qdf = db.Querydefs("NameOfSavedQuery")
'If there are any parameters for the query, you
'would set them before executing it like this:
qdf.Parameters("ParameterName1") = SomeValue
qdf.Parameters("ParameterName2") = SomeValue

'etc, etc.  Then you can execute it:

qdf.Execute

Set qdf = Nothing
db.Close
Set db = Nothing

As I mentioned, the only error messages that would show would be if there was a syntax error with the query, or if you improperly specify the query parameters.

If you are currently using Docmd.OpenQuery, then you should change your code to do it with querydef objects because you have much more control. However, please note that if you do have parameters in the query, and you were using Docmd.OpenQuery you are aware that Access prompts the user for the parameter values. This will not occur when using querydef objects. The user is not prompted for any information. That is why you have to populate the parameters in the .Parameters collection yourself in code. This is a minor drawback, but it means that you may have to put in additional code or forms to collect the needed information from the user.
 
I've used 'DoCmd.SetWarnings False' with my append queries. This gets rid of the messages warning that you're about to append, etc. I don't know, however, if it will kill error messages as well. Maybe worth a shot.

B. - - - -

Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top