开发者

Setting the default value of an Access 97 text field to an empty string

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?


This works:

txtFieldone.AllowZeroLength = True
txtFieldone.DefaultValue = """"""

Not sure what's going on here, but I tested it with a query on = "" and it returns the correct records!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜