ALTER TABLE:添加具有默认值和复选框的新布尔列

发布于 2024-10-21 04:22:50 字数 267 浏览 6 评论 0原文

将布尔数据类型列添加到表中的正确 Access DDL 查询是什么?

到目前为止,我已经看到了如下示例...

ALTER TABLE MyTable ADD MyNewColumName BIT

但它们似乎并不是 100% 正确,因为

  1. Access 不会将复选框控件应用于新添加的列,并且
  2. 该列的允许值似乎是 0-1

What is the correct Access DDL query to add a Boolean datatype column to a table?

So far I've seen examples like the following...

ALTER TABLE MyTable ADD MyNewColumName BIT

but they do not seem to be 100% correct since

  1. Access does not apply the checkbox control to the newly added column, and
  2. the allowed values for that column seem to be 0 and -1

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

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

发布评论

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

评论(2

风月客 2024-10-28 04:22:50

在访问中,是/否数据类型是一个逻辑字段,可以显示是/否、真/假或开/关。当您查看 VBA 代码时,true 和 false 常量相当于 -1 和 0。

如果您使用此字段填充复选框,它将正常工作。

您可以将您的更改语句更改为使用“YESNO”,如下所示:

ALTER TABLE mytable ADD mynewcolumn YESNO

这应该在访问表列中为您提供所需的复选框。

In access the Yes/No data type is a logical field that can display yes/no, true/false, or on/off. When you look at VBA code the true and false constants are equivalent to -1 and 0.

If you use this field to populate a check box it will function properly.

You may be able to Change your alter statement to use "YESNO" as such:

ALTER TABLE mytable ADD mynewcolumn YESNO

That should give you the desired check box in the access table column.

我一向站在原地 2024-10-28 04:22:50

一个 DAO 示例。

''Requires reference to Microsoft DAO 3.6 Object Library
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim db As Database
Dim strSQL As String


Set db = CurrentDb

''Create a table ...
strSQL = "Create Table tblLTD (TheYesNoCheck YesNo, TheYesNoCombo YesNo)"
db.Execute strSQL

''It is now in the table collection, so ...
Set tdf = db.TableDefs("tblLTD")

''Change the way the YesNo fields display.
''A Checkbox
Set fld = tdf.Fields("TheYesNoCheck")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
fld.Properties.Append prp

''A combobox
Set fld = tdf.Fields("TheYesNoCombo")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acComboBox)
fld.Properties.Append prp
''We will need a format
Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
fld.Properties.Append prp

来自: http://wiki.lessthandot.com/index.php/Add_a_Display_Control_ (复选框,_Combobox)_to_a_YesNo_Field

A DAO example.

''Requires reference to Microsoft DAO 3.6 Object Library
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim db As Database
Dim strSQL As String


Set db = CurrentDb

''Create a table ...
strSQL = "Create Table tblLTD (TheYesNoCheck YesNo, TheYesNoCombo YesNo)"
db.Execute strSQL

''It is now in the table collection, so ...
Set tdf = db.TableDefs("tblLTD")

''Change the way the YesNo fields display.
''A Checkbox
Set fld = tdf.Fields("TheYesNoCheck")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
fld.Properties.Append prp

''A combobox
Set fld = tdf.Fields("TheYesNoCombo")
Set prp = fld.CreateProperty("DisplayControl", dbInteger, acComboBox)
fld.Properties.Append prp
''We will need a format
Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
fld.Properties.Append prp

From: http://wiki.lessthandot.com/index.php/Add_a_Display_Control_(Checkbox,_Combobox)_to_a_YesNo_Field

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