Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA - Reset ID sequence in table

Hi

In Access VBA I have a table that I use to create a number sequence used for invoices. Sometimes things go wrong and I need to reset the number order of the table. The problem is that the following code tries to insert a record that is already there. How can I get around this?


Sub oReset_Invoice_Number()


Dim oLastID As Integer: oLastID = DMax("ID", "Invoice Numbers")

Dim oNextIDMinusOne As Integer: oNextIDMinusOne = oResetNextIDTo - 1


'S = "INSERT INTO [Invoice Numbers] (ID, [User], [Date Time Stamp]) VALUES (0, 'Reset Code', #01/01/1999#)"


DoCmd.RunSQL (S)


End Sub


ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark 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
SOLUTION
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
SOLUTION
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