J
jhicsupt
I am not that great in Access. I found this code to reset the Autonumber
field in a table. However I am unsure of how to substitute my fields in the
code.
Table Name = IP-1
Autonumber field in Table = "Primary"
Can you tell me how to substitute the Table name and the autonumber field in
the below code?
Thanks in advance.
Private Sub DeleteData()
Dim db As DAO.Database
Dim Rec As DAO.Recordset
Dim a As Long
Set db = CurrentDb()
Set Rec = db.OpenRecordset("YourTable", dbOpenDynaset)
?Make sure there are records to delete
If Not Rec.EOF Then
Rec.MoveFirst
Do Until Rec.EOF
Rec.Delete
Rec.MoveNext
Loop
End If
?Set a to the number before the number you want to start with
?Set it to 0 if you want to start at 1
?This will start the count at 15
a = 14
Rec.AddNew
'Set your autonumber field to a
Rec![ID] = a
?Make sure you use data that matches Field(1)
Rec.Fields(1) = "a"
?Update it then delete it
Rec.Update
Rec.MoveFirst
Rec.Delete
Rec.Close
Set Rec = Nothing
End Sub
field in a table. However I am unsure of how to substitute my fields in the
code.
Table Name = IP-1
Autonumber field in Table = "Primary"
Can you tell me how to substitute the Table name and the autonumber field in
the below code?
Thanks in advance.
Private Sub DeleteData()
Dim db As DAO.Database
Dim Rec As DAO.Recordset
Dim a As Long
Set db = CurrentDb()
Set Rec = db.OpenRecordset("YourTable", dbOpenDynaset)
?Make sure there are records to delete
If Not Rec.EOF Then
Rec.MoveFirst
Do Until Rec.EOF
Rec.Delete
Rec.MoveNext
Loop
End If
?Set a to the number before the number you want to start with
?Set it to 0 if you want to start at 1
?This will start the count at 15
a = 14
Rec.AddNew
'Set your autonumber field to a
Rec![ID] = a
?Make sure you use data that matches Field(1)
Rec.Fields(1) = "a"
?Update it then delete it
Rec.Update
Rec.MoveFirst
Rec.Delete
Rec.Close
Set Rec = Nothing
End Sub