如何在 VBA 中创建带有复选框字段的 MS Access table
How to create an MS Access table with a checkbox field in VBA
我想在 VBA 中使用复选框字段动态创建 MS Access table。将字段 属性 设置为复选框适用于现有的 table:
Set dbs = CurrentDb()
Set tdf = dbs.TableDefs("myTable")
Set fld = tdf.CreateField("myField", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))
但是,当 table 是动态创建时,它不起作用。
Set dbs = CurrentDb()
Set tdf = dbs.CreateTableDef("myTable")
Set fld = tdf.CreateField("myField", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))
dbs.TableDefs.Append tdf
有人知道这段代码有什么问题吗?或者,如果尚未创建 table 时完全可以设置复选框 属性。
这对我有用:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb()
Set tdf = dbs.CreateTableDef("myTable")
Set fld = tdf.CreateField("myField1", dbBoolean)
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
Set fld = tdf.CreateField("myField2", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
我想在 VBA 中使用复选框字段动态创建 MS Access table。将字段 属性 设置为复选框适用于现有的 table:
Set dbs = CurrentDb()
Set tdf = dbs.TableDefs("myTable")
Set fld = tdf.CreateField("myField", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))
但是,当 table 是动态创建时,它不起作用。
Set dbs = CurrentDb()
Set tdf = dbs.CreateTableDef("myTable")
Set fld = tdf.CreateField("myField", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))
dbs.TableDefs.Append tdf
有人知道这段代码有什么问题吗?或者,如果尚未创建 table 时完全可以设置复选框 属性。
这对我有用:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb()
Set tdf = dbs.CreateTableDef("myTable")
Set fld = tdf.CreateField("myField1", dbBoolean)
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
Set fld = tdf.CreateField("myField2", dbBoolean)
tdf.Fields.Append fld
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)