set seed on msaccess autonumber

G

Guest

I am trying to use the code in the Microsoft Knowledge Base Article - 287756
to set the seed in an autonumber field.
This code is as follows:
Function ChangeSeed(strTbl As String, strCol As String, lngSeed As Long) As
Boolean
'You must pass the following variables to this function.
'strTbl = Table containing autonumber field
'strCol = Name of the autonumber field
'lngSeed = Long integer value you want to use for next AutoNumber.

Dim cnn As ADODB.Connection
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column

'Set connection and catalog to current database.
Set cnn = CurrentProject.Connection
cat.ActiveConnection = cnn

Set col = cat.Tables(strTbl).Columns(strCol)

col.Properties("Seed") = lngSeed
cat.Tables(strTbl).Columns.Refresh
If col.Properties("seed") = lngSeed Then
ChangeSeed = True
Else
ChangeSeed = False
End If
Set col = Nothing
Set cat = Nothing
Set cnn = Nothing

End Function

On the statement col.Properties("Seed") = lngSeed I get the error:
Run time error -21474676239 (80000-4005) Invalid argument
I checked my references and they appear OK
Any ideas,
Thanks
 
A

Allen Browne

Are you certain that strCol is an AutoNumber field?
Test the Autoincrement property of the column.
Also, see if you can read its Seed property.

If that does not identify the problem, check out whether you need an update
of msadox.dll. You can discover where the file is by opening the Immediate
Window (Ctrl+G in Access), and entering:
? References("ADOX").FullPath

Here's what I use to set the seed:
http://allenbrowne.com/func-ADOX.html#SetSeed

If you can't get that to work, here's an alternative approach using DDL
instead:
http://allenbrowne.com/func-DDL.html#AdjustAutoNum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top