所以我有以下VB在默认工作区中创建一个访问文件,创建一个表,在该表中创建一些字段...只需要知道将第一个数据类型/字段设置为自动编号的语法。 .GUID,Counter等在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
所以在这一行: set fldMain = tblMain.CreateField(“ID”,dbInteger) 我需要用VB重新配置为autonumber属性的东西替换dbInteger。 我已经尝试过GUID,Counter,Autonumber,AutoIncrement ....不幸的是,这些都不起作用
任何人都知道我在这里缺少的语法吗?
谢谢, 贾斯汀
答案 0 :(得分:1)
请参阅访问网站上的Creating an AutoNumber field from code。
以下是该链接页面的关键行:
Set db = Application.CurrentDb
Set tdf = db.TableDefs(strTableName)
' First create a field with datatype = Long Integer '
Set fld = tdf.CreateField(strFieldName, dbLong)
With fld
' Appending dbAutoIncrField to Attributes '
' tells Jet that its an Autonumber field '
.Attributes = .Attributes Or dbAutoIncrField
End With
With tdf.Fields
.Append fld
.Refresh
End With
顺便说一下,你所做的不是DDL。