troubleshooting Question

Reseting Autonumber Error

Avatar of billcute
billcute asked on
Microsoft Access
12 Comments1 Solution650 ViewsLast Modified:
The module below is for resetting an Autonumber. When I clicked a form based button with the call, I usually get the error code below. How do I resolve the error.

Run-time Error '-2147217858 (80040e3e)'
"Cannot define field more than once"

...and debug highlighted:
cat.Tables("tblUserLog").Columns.Append col

....from the module below
' ******************
Option Compare Database
Dim cat As New ADOX.Catalog

Function AddAutoNumberField()
Dim cat As New ADOX.Catalog
Dim col As New ADOX.Column
cat.ActiveConnection = CurrentProject.Connection
With col
    .Name = "LogID"
    .Type = adInteger
    Set .ParentCatalog = cat
    .Properties("AutoIncrement") = True
    .Properties("Seed") = CLng(10)
    .Properties("Increment") = CLng(10)
End With
cat.Tables("tblUserLog").Columns.Append col
Set cat = Nothing
Set col = Nothing
End Function

I placed the call to the function in an "On Click Event" shown below.

Private Sub btnResetAutonumber_Click()
Call AddAutoNumberField
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros