Solved

checkbox column Access VBA

Posted on 2014-04-21
12
1,469 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

808 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