Autonumber fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Some more needed for a VBA novice!

In my code, I create tables by using CREATE TABLE in a DoCmd.RunSQL
statement. This has worked well - until today when I need an Autonumber
field. What's the best way of creating a table with the first field as an
autonumber?

Any help would be much appreciated - as ever!

Jim Jones
Botswana
 
Use COUNTER as the field type in your string.

This kind of thing:
CREATE TABLE Table1
(Table1ID COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, Field2 TEXT(50);

For a list of the field type names to use in DDL queries as compared to the
Access interface, DAO, and ADOX, this link contains a reference comparision:
Field type names
at:
http://allenbrowne.com/ser-49.html
 
Jim Jones said:
Some more needed for a VBA novice!

In my code, I create tables by using CREATE TABLE in a DoCmd.RunSQL
statement. This has worked well - until today when I need an
Autonumber field. What's the best way of creating a table with the
first field as an autonumber?

Any help would be much appreciated - as ever!

Jim Jones
Botswana

The following should work

docmd.RunSQL "CREATE TABLE mytable (id COUNTER, test TEXT(25))"

For more info, lookup the COUNTER datatype in this article (watch for
linebreaks in the link)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acintsql.asp

Some of these needs to be executed through ADO, for instance

Currentproject.Connection.Execute _
"CREATE TABLE mytable (id INT IDENTITY, test Varchar(25))"
 
Back
Top