R
Roy Goldhammer
Hello there
I have table.
Is there a way to add auto number field to table with vb code?
I have table.
Is there a way to add auto number field to table with vb code?
Roy said:Is there a way to add auto number field to table with vb code?
Roy said:The reason i need it is for importing data from excel. In the import from
excel wizart there is a way to add key field (an autonumber)
Is there a way to do this with code?
onedaywhen said:Roy said:The reason i need it is for importing data from excel. In the import from
excel wizart there is a way to add key field (an autonumber)
Is there a way to do this with code?
With CurrentProject.Connection
.Execute _
"SELECT *" & _
" INTO MyNewTable" & _
" FROM [Excel 8.0;HDR=YES;IMEX=1;Database=C:\db.xls].[Sheet1$];"
.Execute _
"ALTER TABLE MyNewTable ADD MyNewCol" & _
" INTEGER IDENTITY(1,1);"
End With
Jamie.
Terry said:Assuming that the Excel import already has a unique key
what would be the SQL to change that imported column to be the primary key
within the Access table?
Jamie Collins said:Assuming that the Excel import already has a unique key
what would be the SQL to change that imported column to be the primary key
within the Access table?
With CurrentProject.Connection
.Execute _
"SELECT key_col, data_col" & _
" INTO MyNewTable" & _
" FROM [Excel 8.0;HDR=YES;IMEX=1;Database=C:\db.xls].[Sheet1$];"
.Execute _
"ALTER TABLE MyNewTable ADD CONSTRAINT pk__mynewtable" & _
" PRIMARY KEY (key_col);"
End With
Jamie.