VB如何用DAO代码在ACCESS数据表中创建自动增一字段“id”?
VB如何用DAO代码在ACCESS数据表中创建自动增一字段“id”?
类似以下的方法:
Set g_id = g_tb.CreateField( , )
g_id.AllowZeroLength = False '该字段值允许空字符串
g_tb.Fields.Append g_id
[解决办法]
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