Full Version: Insert error
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
jorgeng
I am trying to insert a post which already exist. If it exists i don't want to write the post in the table.

Doing this is by select case in errorhandler
My problem is that i don't get a chance to taking care of the sql-error code since i am doing DoCmd.RunSQL (strSQL).

The sql-code:

strSQL = "INSERT INTO Rapp_Temp"
strSQL = strSQL & " ([ID-PROJEKTDELTAGARE], [DA-AR], [ID-AKTIVITET], [ID-PROJEKT], [BE-PROJEKT], [BE-AKTIVITET])"
strSQL = strSQL & " VALUES (" & TidrappTab(ixa, 2) & ", " & TidrappTab(ixa, 6) & ", " & TidrappTab(ixa, 1) & ","
strSQL = strSQL & " " & id_proj & ", '" & be_proj & "', '" & be_akt & "');"

DoCmd.RunSQL (strSQL)


When i use
Set qdf = dbThis.CreateQueryDef("", strSQL)
Set rst = qdf.OpenRecordset(dbOpenSnapshot)

i came to errorhandler where i can use

errorhandler:
Select Case Err.Number
Case 3021
plantemp_koll = 0
Resume Next
Case Else
MsgBox "Error="

Anyone knowing how to handle "post exists" and then continuing with next post?

Thanks
gideon
Perhaps you should rather check to see if the record exists first.

If it does not then you can post. That way you avoid a failure error.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.