Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create an autonumber ID field with coding

Status
Not open for further replies.

drctx

IS-IT--Management
May 20, 2003
226
US
i want to create an autonumber ID field in an existing table, but when i execute the code i get this error message:

run-time error '3293': syntax arror in ALTER TABLE statment.

Private Sub Command0_Click()
Dim tblName As String
Dim SQLstr, sql1, sql2 As String
tblName = "TCRM File"
sql1 = "alter table add"
sql2 = "ID autonumber;"
SQLstr = sql1 & vbCrLf & sql2
DoCmd.RunSQL SQLstr
DoCmd.OpenTable tblName
End Sub
 
i fixed one problem. i didn't have the table name in the statement. i can get it to work with inserting
ID text(10);

is there a way to set the datatype to autonumber?
 
i found it. use autoincrement instead of autonumber in the sql string.
sql1 = "alter table [TCRM File] add"
sql2 = "ID AUTOINCREMENT;"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top