Brian H
Brian H

Reputation: 27

Setting Auto Increment Start Value as a Variable in Access

I've looked around online but can't find any clear answers for this. Is it possible to set the starting value of an Auto Increment field to a variable (example to follow) in MS Access VBA?

Private Sub Command10_Click()
Dim dbs As Database
Set dbs = CurrentDb
Dim tblTempMinID As String

tblTempMinID = "DMax(EntryID, tblCalendar) + 1"
dbs.Execute "ALTER TABLE tblTemp ALTER COLUMN EntryID AUTOINCREMENT(tblTempMinID)"

End Sub

I'm currently getting an error in field definition with the above code. Still doing research, but I figured it wouldn't hurt to put this out here.

Upvotes: 0

Views: 1827

Answers (1)

Slubee
Slubee

Reputation: 406

Assuming you want to increment by 1:

dbs.Execute "ALTER TABLE tblTemp ALTER COLUMN EntryID AUTOINCREMENT(" & tblTempMinID & ",1)"

Upvotes: 1

Related Questions