Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 25th, 2005, 09:15 PM
Registered User
 
Join Date: Jan 2005
Location: , , Denmark.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADOX: Changing the view of a boolean

I'm creating a table with adox, and having several columns set to boolean.
I do this in the creation-phase before I Append the column.
col.Type = adBoolean

However. If I open the table, the boolean-columns does not show as a check-box as I want them to... :(
They simply just show as a text-field as if it was any other type of field.

How do I change the view to checkbox rather than textfield???

Thanks
Thomas
Reply With Quote
  #2 (permalink)  
Old January 25th, 2005, 11:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Thomas,

I have a hunch that this might be one of those obscure cases illustrating the point that DAO and Jet were made for each other, ADO/ADOX and Jet weren't. You can add the checkbox to your Boolean field display in DAO using the CreateProperty method of the Field object. The ADO Field object doesn't support a CreateProperty method. In DAO, iterate through your TableDef's Fields collection adding the CheckBox display control like this:

For Each fld In tdf.Fields
       If fld.Type = dbBoolean Then
           Set prp = fld.CreateProperty("DisplayControl", dbLong, 106)
           fld.Properties.Append prp
       End If
Next fld

HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old May 31st, 2006, 07:16 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bob Bedell

thanks for the POST, I was looking for this as well.

however, dbLong is wrong type for this to work.

here full code that is working:

Dim dbs As DAO.Database
  Dim tdf As DAO.TableDef
  Dim fld As DAO.Field
  Dim prp As DAO.Property

  Dim sDbPath$
  Dim sDbPassword$
  Dim sTableName$

  sDbPath$ = "c:\vAdoDb.mdb" 'this is coming from my complete OCX Library for Access 2000
  sDbPassword$ = ""
  sTableName$ = "tbl_Test"


  Set dbs = OpenDatabase(sDbPath$, False, False, "MS Access;PWD=" & sDbPassword$ & ";")
    Set tdf = dbs.TableDefs(sTableName$)
    For Each fld In tdf.Fields
      If fld.Type = dbBoolean Then
        Set prp = fld.CreateProperty("DisplayControl", dbInteger, 106)
        fld.Properties.Append prp

        Set prp = fld.CreateProperty("Format", dbText, "Yes/No")
        fld.Properties.Append prp
' more property you can mess with
' Set prp3 = fld.CreateProperty("ColumnWidth", dbInteger, -1)
' Set prp4 = fld.CreateProperty("ColumnOrder", dbInteger, 0)
' Set prp5 = fld.CreateProperty("ColumnHidden", dbBoolean, False)
      End If
    Next fld
  dbs.Close

  Set dbs = Nothing
  Set tdf = Nothing
  Set fld = Nothing
  Set prp = Nothing

Reply With Quote
  #4 (permalink)  
Old January 6th, 2007, 07:02 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to the post above and a bit of tinkering, I managed to get checkboxes into my ADO created Access database. However, I did have to alter things slightly to get it to work in Visual Basic 2005. This code runs after I've pulled in the data into the created Access MDB using ADO and then closed the connection.

I also added another 'For Each' statement to loop through each table in the database after going through each table's specific set of fields.

Here's the code:

        Dim dbs As dao.Database
        Dim tdf As dao.TableDef
        Dim fld As dao.Field
        Dim prp As dao.Property
        Dim dbe As New dao.DBEngine


        Dim sDbPath$
        Dim sDbPassword$

        sDbPath$ = "C:\YourDatabase.mdb" 'this is coming from my complete OCX Library for Access 2000
        sDbPassword$ = ""

        dbs = dbe.OpenDatabase(sDbPath$, False, False, "MS Access;PWD=" & sDbPassword$ & ";")
        For Each tdf In dbs.TableDefs
            For Each fld In tdf.Fields
                If fld.Type = dao.DataTypeEnum.dbBoolean Then
                    prp = fld.CreateProperty("DisplayControl", dao.DataTypeEnum.dbInteger, 106)
                    fld.Properties.Append(prp)

                    prp = fld.CreateProperty("Format", dao.DataTypeEnum.dbText, "Yes/No")
                    fld.Properties.Append(prp)
                    ' more property you can mess with
                    ' Set prp3 = fld.CreateProperty("ColumnWidth", dbInteger, -1)
                    ' Set prp4 = fld.CreateProperty("ColumnOrder", dbInteger, 0)
                    ' Set prp5 = fld.CreateProperty("ColumnHidden", dbBoolean, False)
                End If
            Next fld
        Next tdf
        dbs.Close()

        dbs = Nothing
        tdf = Nothing
        fld = Nothing
        prp = Nothing

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADOX speedlearner BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 June 23rd, 2006 04:15 PM
Create a Table using ADOX JDrown Access VBA 7 April 12th, 2006 03:52 AM
ADOX problem toshesh VB Databases Basics 1 December 23rd, 2005 10:34 AM
ADOX/MDAC Problem r4ross Access VBA 2 December 2nd, 2005 10:39 AM
Dynamic queries without ADOX gpet Access 0 June 10th, 2005 01:33 AM



All times are GMT -4. The time now is 05:21 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.