Function DeleteAllAndResetAutoNum(strTable As String) As Boolean
'Purpose: Delete all records from the table, and reset the AutoNumber using ADOX.
' Also illustrates how to find the AutoNumber field.
'Argument: Name of the table to reset.
'Return: True if sucessful.
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column
Dim strSql As String
'Delete all records.
strSql = "DELETE FROM [" & strTable & "];"
CurrentProject.Connection.Execute strSql
'Find and reset the AutoNum field.
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(strTable)
For Each col In tbl.Columns
If col.Properties("Autoincrement") Then
col.Properties("Seed") = 1
DeleteAllAndResetAutoNum = True
End If
Next
End Function
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
if you delete ALL the records in the table, then do a Compact and Repair, the AN will reset to zero. However, you must delete ALL the records.
mx