将 Access 97 文本字段的默认值设置为空字符串
使用 DAO 和 VB6,我尝试将 access 97 文本字段的默认值设置为空字符串(而不是 Null):
Dim newField as DAO.Field
Set newField = myTablelDef.CreateField("NewField", dbText, 10)
newField.DefaultValue=""
但是,这被解释为 Null,并且未指定 NewField 的新记录将 Null 作为其值而不是空字符串。如果我将值更改为“默认”,这会反映在新记录中,因此代码本身是正确的。我知道可以将空字符串而不是 Null 分配给文本字段,那么它是如何完成的呢?
Using DAO and VB6 I try to set the default value of an access 97 text field to an empty string (rather than Null) thus:
Dim newField as DAO.Field
Set newField = myTablelDef.CreateField("NewField", dbText, 10)
newField.DefaultValue=""
However, this is interpreted as Null and new records for which the NewField is not specified get Null as their value in stead of an empty string. If I change the value to, say, "Default" this is reflected in new records, so the code in itself is correct. I know that it IS possible to assign an empty string rather than Null to a Text field, so how is it done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可行的:
不确定这里发生了什么,但我用 = "" 上的查询测试了它,它返回了正确的记录!
This works:
Not sure what's going on here, but I tested it with a query on = "" and it returns the correct records!
您需要设置
newField.AllowZeroLength = True
。在 Access97 中所有文本和备注字段将此设置为 false。 2000年&超出则相反。
这是通过代码将它们全部设置为 true 的方法。
You'll need to set the
newField.AllowZeroLength = True
.In Access97 all text & memo fields have this set to false. In 2000 & beyond it's the opposite.
Here's a way to set them all to true via code.
我同意你的观点,设置它=“”不起作用。设置AllowZeroLength = true,并在每次插入时设置该字段=“”。并不完美,但它会起作用。
I agree with you that setting it = "" does not work. Set AllowZeroLength = true, and on each insert, set that field = "". Not perfect, but it will work.