Solved

checkbox column Access VBA

Posted on 2014-04-21
12
1,481 Views
Last Modified: 2014-04-21
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
0
Comment
Question by:Rayne
12 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 40013608
Can you provide what code you have so far so we can see what you're doing?

Thanks!
ab
0
 

Author Comment

by:Rayne
ID: 40013612
CurrentDb.TableDefs("tblPass").Fields("BoolField").DisplayControl = acCheckBox

doesnt work
0
 

Author Comment

by:Rayne
ID: 40013626
And I need to appear as real checkboxes, not as zeros as they are now…
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Rayne
ID: 40013638
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
 

Author Comment

by:Rayne
ID: 40013640
is adding a new column but that column is not appearing as checkbox...
0
 
LVL 84
ID: 40013742
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
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 40013771
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
 

Author Comment

by:Rayne
ID: 40013912
that's perfection Aikimark,

that's perfection, thank you, you saved the day :)
0
 

Author Comment

by:Rayne
ID: 40013917
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
 

Author Comment

by:Rayne
ID: 40013927
also AikiMark,

what do you mean here programmatically by saying append ?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40013936
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
 

Author Comment

by:Rayne
ID: 40014006
great, nice explanation Sire
 thank you :)
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question