checkbox column Access VBA

Hello,

I am trying to add a new checkbox column in tblBox.

The new column name should be “myC”
I am trying to use vba and ddl but no success so far…can someone help?

Thank you
RayneAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
aikimarkConnect With a Mentor Commented:
I've encountered similar problems trying to supply certain attributes and properties at the time I created an object, such as a field.  I think this is another example of the same software quirk.

I think you'll have to do that in three statement -- create both the field and the property and then append the property.  Your code comes very close.
Example:
    Dim db As DAO.Database
    Set db = CurrentDb

    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim propThing As Property    'new

    Set fld = tdf.CreateField(colName, dbBoolean)
    tdf.Fields.Append fld

    Set propThing = fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)

    fld.Properties.Append propThing

    db.Close
    Set db = Nothing

Open in new window

0
 
Anthony BerenguelCommented:
Can you provide what code you have so far so we can see what you're doing?

Thanks!
ab
0
 
RayneAuthor Commented:
CurrentDb.TableDefs("tblPass").Fields("BoolField").DisplayControl = acCheckBox

doesnt work
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
RayneAuthor Commented:
And I need to appear as real checkboxes, not as zeros as they are now…
0
 
RayneAuthor Commented:
Dim db As DAO.Database
    Set db = CurrentDb

    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field

    Set tdf = db.TableDefs("tblpass")
    Set fld = tdf.CreateField(colName, dbBoolean)
    tdf.Fields.Append fld

    fld.Properties.Append fld.CreateProperty(colName, dbInteger, CInt(acCheckBox))

    db.Close
    Set db = Nothing
0
 
RayneAuthor Commented:
is adding a new column but that column is not appearing as checkbox...
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What do you mean it doesn't appear as checkbox? Do you mean when you view the table, or when you drag into onto a form?
0
 
RayneAuthor Commented:
that's perfection Aikimark,

that's perfection, thank you, you saved the day :)
0
 
RayneAuthor Commented:
Hello Aikimark,

I really liked your approach,

here is anther one if you are interested :)
http://www.experts-exchange.com/Database/MS_Access/Q_28417181.html
0
 
RayneAuthor Commented:
also AikiMark,

what do you mean here programmatically by saying append ?
0
 
aikimarkCommented:
what do you mean here programmatically by saying append ?
You actually use an Append method for both the field object (to the tabledef's fields collection) and the property (to the field's properties collection).

Your solution is in code, rather than a manual process.  That is why I might use a "programmatic" descriptor.
0
 
RayneAuthor Commented:
great, nice explanation Sire
 thank you :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.