ALTER TABLE FLAT ADD COLUMN selectID YesNo DISPLAY CONTROL 'CheckB

G

Guest

Hi,
I am running with a problem where I want to add a CheckBox column to a table.
I have been able to add the column, but the default 'Display Control' is set
to: TEXT BOX, how can I change the 'Display Control' to: CHECKBOX? can this
be done?

currently I am using the query:
ALTER TABLE FLAT ADD COLUMN selectID YesNo;

any help is appreciated in advance.. thanks
 
A

Allen Browne

You cannot set the DisplayControl property of the field in a table via a DDL
query statement.

DAO is the only way to set this property. Your code will need to
CreateProperty(), with the name "DisplayControl", of type dbInteger, and
value CInt(acCheckBox).
 
G

Guest

Hi Allen,

first of all thank you for the response, I'm not sure what you mean. Can
this be done through visual basic? So I have the following code:

DoCmd.RunSQL "ALTER TABLE FLAT ADD COLUMN selectID YESNO;

then what would I need to do?, I'm a bit lost with the advice.. can I use it
in VB?
I am trying to automate the process as much as possible.. so I'm not sure
how the CreateProperty(), with the name "DisplayControl", of type dbInteger,
and
value CInt(acCheckBox) will modify the Display Control in the table.

again Thank you for your help
 
A

Allen Browne

The RunSql approach cannot do it.

You need code like this:

Function AddYN()
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

'Create the field.
Set tdf = DBEngine(0)(0).TableDefs("flat")
Set fld = tdf.CreateField("SelectID", dbBoolean)
tdf.Fields.Append fld

'Set the property
fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger,
CInt(acCheckBox))
End Function
 
G

Guest

Hey Allen,

Thank you a bunch.. it did help and worked!.. appreciate your help!
have a good weekend..
 

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