2

所以我有下面的VB,它在默认工作区创建一个访问文件,创建一个表,在该表中创建一些字段......只需要知道将第一个数据类型/字段设置为自动编号的语法......GUID,计数器等不会像在 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 重新转换为自动编号属性的东西替换 dbInteger。我试过 GUID、Counter、Autonumber、AutoIncrement....不幸的是这些都不起作用

有人知道我在这里缺少的语法吗?

谢谢,贾斯汀

4

1 回答 1

1

请参阅The access Web 上的从代码创建自动编号字段。

以下是该链接页面的关键行:

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。

于 2010-05-17T22:06:40.400 回答