VBA for Access 2003 - 用于创建访问文件的 DDL:设置自动编号数据类型

发布于 2024-09-02 02:14:19 字数 849 浏览 15 评论 0原文

所以我有下面的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

因此在这一行中: 设置 fldMain = tblMain.CreateField("ID", dbInteger) 我需要将 dbInteger 替换为 VB 识别为自动编号属性的内容。 我已经尝试过 GUID、计数器、自动编号、自动增量......不幸的是,这些工作都没

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

谢谢, 贾斯汀

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舂唻埖巳落 2024-09-09 02:14:19

请参阅访问网站上的从代码创建自动编号字段

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

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。

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

Here are the key lines from that linked page:

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

BTW, what you're doing is not DDL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文