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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap a key violation error in Code? 1

Status
Not open for further replies.

pdupreez

Technical User
May 16, 2001
49
ZW
I use an "insert " sql statement, and sometimes enter data into the table which already exists. No problem if I can trap the Access97 error box that comes up if an append/update error occurs. I cannot however seem to trap the error, even with an "on error" routine. Any Ideas??
 
You will have to use the RecordsAffected property to check your action queries. Something like:

Code:
Private Sub Command0_Click()
On Error GoTo errHandler
    With CurrentDb
        .Execute "INSERT INTO tbl1 (aNumber) Values (6)"
        If .RecordsAffected > 0 Then
            MsgBox "success"
        Else
            MsgBox "Failed"
        End If
    End With
    Exit Sub
errHandler:
    MsgBox Err.Description
End Sub

I hope this helps,
Rewdee
 
Hi Rewdee

It works fine, as I can check vs expected affected and actual and report on difference. Great

Thanks
Pieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top