Setting the Display Control property of a table field to Check Box

Posted on 2006-05-24
Last Modified: 2010-05-18
The following code is my attempt to set the Display Control property = "Check Box" for a table field named MyCheckBox which I am adding to the table trefLinkList. I get the error Data Type Mismatch on the line that is supposed to set the DisplayControl property:

 Set prp = tdf.Fields("MyCheckbox").CreateProperty("DisplayControl", dbInteger, acCheckBox)

Dim db As Database
Dim tdf As TableDef, tf As Field
Dim prp As Property
 Set db = CurrentDb
 Set tdf = db.TableDefs("trefLinkList")
 With tdf
  .Fields.Append .CreateField("MyCheckbox", dbBoolean)
 End With
 Set tdf = db.TableDefs("trefLinkList")
 Set prp = tdf.Fields("MyCheckbox").CreateProperty("DisplayControl", dbInteger, acCheckBox)
 tdf.Fields(tf.Name).Properties.Append prp
Question by:paulmcneil
    LVL 61

    Accepted Solution

    You haven't defined tf, which you are using in the following line:
    >tdf.Fields(tf.Name).Properties.Append prp

    Your code works beatifully in Access 2003, by changing this line to:
    tdf.Fields("MyCheckbox").Properties.Append prp


    Author Comment

    I took your advice and now I get the data type mismatch on

    Set prp = tdf.Fields("MyCheckbox").CreateProperty("DisplayControl", dbInteger, acCheckBox)
    LVL 61

    Expert Comment

    What version of access are you using?
    LVL 34

    Expert Comment

    Can you use this?
            strSQL = "Alter Table tbl_Specs ADD COLUMN ["ColumnName"] YesNo"
            CurrentDb.Execute strSQL

    Author Comment

    I'm using Access 2003 SP2
    LVL 61

    Expert Comment


    Thats the same version I'm using.  When something works on one machine but not another, the first thing I check is references (although I'd expect a different error message if it were a reference problem).  Anyhow to rule that out as a possibility, open a VBA module and go to Tools -> References.  Do you see anything flagged as MISSING?
    LVL 58

    Assisted Solution

    Hello paulmcneil

    Both ADODB and DAO have an object type called "Property". If your "ActiveX Data Objects" is loaded first in the list of references (it probably is), you would get a type mismatch. You need to be explicit:

        Dim prp As DAO.Property

    Your code will work fine with that change.
    Gool luck!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now