William, this is odd. The only obvious thing would be if the code did not
actually delete all the records from the table.
ADOX is pretty buggy, but Ver 2.8 should be fine for this.
The code has correctly identified the column, and it does have a Seed
property if you can view the current value.
You are assigning an integer to it, which VBA should convert to a long
without problem, so it is the correct type for the property.
The "invalid argument" message might make sense if there are records in the
table using a higher value, and so ADOX recognised that 1 was too small a
number to let you assign.
Can you verify that the records have all gone at this point? There are none
with related records elsewhere that prevent them being deleted? No pending
transactions?
That's the only thing I can think of. Hope it leads you in a useful
direction.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
WJBR said:
What error number and message do you see?
Run-time error '-2147467259(80004005)':
Invalid argument
What version of the ADOX library are you using?
microsoft ADO Ext. 2.8 for DDL and security
Is the code identifying the correct AutoNumber column before it fails?
Yes, it gives the first number if you run the mouse over it.
col.properties("seed")=31080
If you open the table in design view, what are the properties of the
AutoNumber field?
Field Size "Long Integer" and New Values "Increment".
Appreciate the help
Many thanks
William
Allen Browne said:
What error number and message do you see?
Run-time error '-2147467259(80004005)':
Invalid argument
What version of the ADOX library are you using?
microsoft ADO Ext. 2.8 for DDL and security
Is the code identifying the correct AutoNumber column before it fails?
Yes, it gives the first number if you run the mouse over it.
col.properties("seed")=31080
If you open the table in design view, what are the properties of the
AutoNumber field? Normally you would expect Field Size to be "Long
Integer",
and New Values to be "Increment".
Field Size "Long Integer" and New Values "Increment".
Function DeleteAllAndResetAutoNum(strTable As String) As Boolean
'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
Have tried the code above taken from this website but always stalls on
col.Properties("Seed") = 1 - Invalid argument? Compiles ok.
Many thanks
William