append error message

S

seeker

I have an insert query that when the user runs it an append error message is
seen on screen. I would like my error capturing to catch that error and then
create a message that is more understandable to the user. Such as " A record
with this ID already exists in table please select a different record." How
can this be done?
 
M

MGFoster

seeker said:
I have an insert query that when the user runs it an append error message is
seen on screen. I would like my error capturing to catch that error and then
create a message that is more understandable to the user. Such as " A record
with this ID already exists in table please select a different record." How
can this be done?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have to run the query from a VBA procedure. E.g. (a CommandButton
named "OK" - its Click event):

Private Sub cmdOK_Click()

On Error GoTo err_

CurrentDb.QueryDefs("Query Name").Execute dbFailOnError

Exit Sub

err_:
Dim strMsg As String
If err = 3022 Then ' Duplicate record
strMsg = "A record with this ID already exists in table " & _
"please select a different record."
Else
strMsg = err.Description
End If

MsgBox strMsg, vbExclamation

End Sub

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSiBklYechKqOuFEgEQLoXQCg2tdy+2LKaC6jA0qKckMiipdk08IAni64
k3QhctJH+An/xf6hNy719Ei9
=p4xR
-----END PGP SIGNATURE-----
 

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