读书人

VB怎么用DAO代码在ACCESS数据表中创建

发布时间: 2012-03-06 20:47:55 作者: rapoo

VB如何用DAO代码在ACCESS数据表中创建自动增一字段“id”?
VB如何用DAO代码在ACCESS数据表中创建自动增一字段“id”?

类似以下的方法:
Set g_id = g_tb.CreateField( , )
g_id.AllowZeroLength = False '该字段值允许空字符串
g_tb.Fields.Append g_id

[解决办法]

VB code
g_id.Attributes = dbAutoIncrField
[解决办法]
Dim db As Database
Dim td As TableDef
Dim fd As Field

Set db = CurrentDB
Set td = CurrentDB.CreateTableDef("tblTestAutonum")

Set fd = td.CreateField("fldTestAutonum")
fd.Type = dbLong
' Here is the real trick. Have to set the attributes.
fd.Attributes = dbAutoIncrField
td.Fields.Append fd
db.TableDefs.Append td

Set fd = Nothing
Set td = Nothing
Set db = Nothing

读书人网 >VB

热点推荐