views:

32

answers:

1

So I have the below VB that creates an access file in the default workspace, creates a table, create some fields in that table...just need to know the syntax for setting the first data type/field to autonumber...GUID, Counter, etc will not work as in Access SQL

' error handling usually goes here

dim ws as workspace
dim dbExample as database
dim tblMain as TableDef
dim fldMain as Field
dim idxMain as Index

set ws = workspace(0)

set dbExample = ws.CreateDatabase('string file path')

set tblMain = dbExample.CreateTableDef("tblMain")

set fldMain = tblMain.CreateField("ID", 'right here I do not know what to substitute for dbInteger to get the autonumber type to work )

tblMain.Fields.Append fldMain
etc to create other fields and indexes

so in this line: set fldMain = tblMain.CreateField("ID", dbInteger) i need to replace the dbInteger with something that VB reconizes as the autonumber property. i have tried GUID, Counter, Autonumber, AutoIncrement....unfortunately none of these work

anyone know the syntax I am missing here?

Thanks, Justin

+1  A: 

See Creating an AutoNumber field from code at The access Web.

BTW, what you're doing is not DDL.

HansUp
thanks Hans! I just called it DDL because this O'Reilly book I am learning it out of called it that??
Justin
@Justin Dunno bout that. Wikipedia's description for Data Definition Language is what I thought DDL stands for. Seems to me your O'Reilly example uses VBA to create a table as a substitute for DDL.
HansUp
yeah i think you are right after reading it again. They show examples of Access SQL DDL, and then I think this was the VBA equiv (means to an end so to speak). my bad...just learning this stuff. thanks for the example...i call the function in my sub and it worls great.
Justin
You're not using DDL, you're using DAO, which knows more about Jet/ACE's data types and structures than generic DDL SQL does. Shame on O'Reilly for calling that code DDL.
David-W-Fenton