adding boolean numbers to table but shows 0 instead of check boxes

stephenlecompte
07-06-2004, 09:42 AM
I have the following code to add some fields in an access database:

Private Sub Form_Load()

Dim db As Database
Set db = OpenDatabase("C:\ZZZ OPERATIONS PROGRAMS\orderentry_be.mdb", False, False)
Dim tdf As TableDef
Set tdf = db.TableDefs("tblOrders")
With tdf
.Fields.Append .CreateField("fUnpk", dbBoolean)
.Fields.Append .CreateField("fDebr", dbBoolean)
.Fields.Append .CreateField("fG11", dbBoolean)
End With
MsgBox "Updating done on database... "

Unload Me
End Sub

This has worked before but now when I try to add the above fields they show up with a 0 in the field instead of the normal check box. Not sure as to why this is happening? Any suggestions much appreciated.

MKoslof
07-06-2004, 10:30 AM
Access stores boolean values as type BIT, so 0, -1.To get the Yes/No format, you need to append a Format property. You can also make Access use a checkbox for the boolean field by appending a DisplayControl property.

Something like:


Dim prp As Property
'Add a Boolean field to the table
Set fld = tbfDef.CreateField("FG11", dbBoolean)
tbfDef.Fields.Append fld
'Add a Format property
Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
fld.Properties.Append prp
'Add a DisplayControl property
Set prp = fld.CreateProperty("DisplayControl", dbInteger,acCheckbox)
fld.Properties.Append prp
tbfDef.Fields.Refresh

stephenlecompte
10-21-2004, 12:57 PM
Access stores boolean values as type BIT, so 0, -1.To get the Yes/No format, you need to append a Format property. You can also make Access use a checkbox for the boolean field by appending a DisplayControl property.

Something like:


Dim prp As Property
'Add a Boolean field to the table
Set fld = tbfDef.CreateField("FG11", dbBoolean)
tbfDef.Fields.Append fld
'Add a Format property
Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
fld.Properties.Append prp
'Add a DisplayControl property
Set prp = fld.CreateProperty("DisplayControl", dbInteger,acCheckbox)
fld.Properties.Append prp
tbfDef.Fields.Refresh




If I just wanted to rename a field, instead of adding to it?
Do I use the same .Append property? If so, how?
Thanks,

MKoslof
10-21-2004, 07:26 PM
To rename a field you can use the ADOX..that is probably the most flexible method with Access.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum