Reputation: 27
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
Reputation: 406
Assuming you want to increment by 1:
dbs.Execute "ALTER TABLE tblTemp ALTER COLUMN EntryID AUTOINCREMENT(" & tblTempMinID & ",1)"
Upvotes: 1