Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

Resume Next Question - Dup Record in Database Table

Hello all.  I have some VB code that loops through and inserts records into an access table.   I get to a record that already exists in my table and access throws a error change could not be inserted because of dup key.  Then VB throws a file already open error on the .Update line of the below code.  Should I just do a Resume Next or something?  I dont want to check the DB everytime with a select statement.  Any ideas?

With dbAccessDb.OpenRecordset("tblCustomer", dbOpenDynaset)
                        .AddNew
                        .Fields!Acct = Acct                        
                        .Fields!Cust = Cust
                        .Update
                        .Close
                    End With
ASKER CERTIFIED SOLUTION
Avatar of Nightman
Nightman
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kinger247
Kinger247



Something Like ...


On Error GoTo ErrHandler:

your loop .....

With dbAccessDb.OpenRecordset("tblCustomer", dbOpenDynaset)
  .AddNew
  .Fields!Acct = Acct
  .Fields!Cust = Cust
  .Update
  .Close
End With

ErrHandler:
Resume Next

your loop .....
Avatar of sbornstein2

ASKER

i dont want the overhead of having to check the database each time before the insert
You wouldn't be - you would just handle the error on the insert and resume IF the error was a PK violation