.CreateField Formating

B

bret

Hello,

Im using the string below to add a field to a table, i'd
like the field be formated with the 'nice' little yes/no
box, but am getting what looks like a text field that
says "yes" or "no".... Is there a parameter i need to
add to do this?

Set Field = TDef.CreateField(FldName, dbBoolean)


thanks

bret
 
J

Juan M. Afan de Ribera

Hi,

you need to create the property "DisplayControl" and assing the value 106
(acCheckBox) to it.

Ie. this code will create a new boolean field to the table "MyTable" with
the checkbox format

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property

Set db = CurrentDb
Set tdf = db.TableDefs("MyTable")
' create and append a new field to the table
Set fld = tdf.CreateField("newField", dbBoolean)
tdf.Fields.Append fld
' after append new field create the property
' "DisplayControl" as a checkbox
Set prp = fld.CreateProperty( _
"DisplayControl", dbInteger, acCheckBox)
' append the property to the field
fld.Properties.Append prp

Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

HTH
 
T

Tim Ferguson

Im using the string below to add a field to a table, i'd
like the field be formated with the 'nice' little yes/no
box, but am getting what looks like a text field that
says "yes" or "no".... Is there a parameter i need to
add to do this?

Bear in mind that the format field _only_ affects what is created by
default when you add a field to a form: in other words, it's strictly a GUI
property. If you or your users have access to forms design, then you can
use the Tables design window to add the field (which is _much_ easier than
using code...).

The question is therefore redundant. Either you have use of the GUI -- in
which case you might as well use it --, or you don't -- in which case the
Format property ain't gonna do you no good anyway.

B Wishes



Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top