On Error trap not being triggered

M

mscertified

Here is the code, the first column in the table is the primary key. I get an
Access error window (with a negative error number) instead of the error trap
being triggered. I need to trap duplicate inserts.

Public Sub DupTest()
On Error GoTo ER
Dim strSQL As String
strSQL = "INSERT INTO tblLock (LT,Userid) Values('Q','dcmcspar')"
CurrentProject.Connection.Execute strSQL
CurrentProject.Connection.Execute strSQL
Exit Sub
ER:
MsgBox Err.Description, , Err.Number
End Sub
 
D

Dirk Goldgar

mscertified said:
Here is the code, the first column in the table is the primary key. I get
an
Access error window (with a negative error number) instead of the error
trap
being triggered. I need to trap duplicate inserts.

Public Sub DupTest()
On Error GoTo ER
Dim strSQL As String
strSQL = "INSERT INTO tblLock (LT,Userid) Values('Q','dcmcspar')"
CurrentProject.Connection.Execute strSQL
CurrentProject.Connection.Execute strSQL
Exit Sub
ER:
MsgBox Err.Description, , Err.Number
End Sub


Make sure you don't have the VB option "Break on All Errors" set. When I
run the code, with "Break on Unhandled Errors" set, it goes to the error
handler as it should.
 
M

mscertified

How do I change that option? I looked thru the entire VB reference and no
mention of it.
 
D

Dirk Goldgar

mscertified said:
How do I change that option? I looked thru the entire VB reference and no
mention of it.

In the VB Editor window (not the Access application window), click menu item
Tools -> Options.... On the option dialog, choose the General tab. Among
the options presented is an "Error Trapping" option group.
 

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