Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Yes/No field from VBA?

Status
Not open for further replies.

BobK4UVT

Programmer
Aug 18, 2002
22
0
0
US
I'm trying to create a dbBoolean "Yes/No" field for a table in VBA with the CreateField method. I can create a dbBoolean field easily enough, but I can't get it to have a "Yes/No" property. If I create a table normally in Access in design view, I can define a field as Yes/No with a checkbox lookup. Just trying to figure out how to do the same thing from VBA.

Anyone have any tips?

Thanks in advance ... Bob
 

A Boolean field is one bit. It is designated as 0 or 1, true or false, yes or no. yes or no is simply an Access construct of one or zero. Your definition of Boolean is as far as you are going to get it to go.

You can use a yes/no format to display yes or no if that is what you need.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
thornmastr,

I agree with you there. If I create a Yes/No field in normal design view (not from VBA), then by default the look up type is Check Box, which is precisely what I want. But if I do it from VBA, I get a Yes/No field, but the lookup type is Text Box. So I must be missing something.

The sub I use is:


Public Sub CreateBooleanField(FldName As String, Tabl As TableDef, OrdPos As Integer)

Dim Fld As Field

Set Fld = Tabl.CreateField(FldName, dbBoolean)
Fld.OrdinalPosition = OrdPos
Fld.DefaultValue = 0
Tabl.Fields.Append Fld

End Sub

Have I missed something? All I need for it to do now is to have the lookup property as checkBox instead of TextBox.

Many thanks!

Bob
 
Can't help you with your problem, but just wanted to clarify that Yes/No fields in Access have a true value of -1 and a false value of 0, _not_ 1 for true and 0 for false. I assume it stays the same if the field is defined as boolean and doesn't formally get registered as a Yes/No data type.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top