Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Checkbox to table HOW?

Status
Not open for further replies.

BH

Programmer
Oct 15, 2002
76
GB
Hi

Through vba I would like to add fields to a table. I have managed to add a text field but I am stuggling adding a checkbox field. Is there anyone who can help please!

My code for adding text field:

Sub UpdateTable_Click()
Dim db As DAO.Database
Dim fldNew As String

Set db = OpenDatabase("c:\db1.mdb")
fldNew = "ALTER TABLE tblFIELD ADD column field1 text;"
db.Execute fldNew
db.Close
Set db = Nothing
End Sub
 
IS this any help?

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi HarleyQuinn

That was a great help thank you very much. I can now open up a db, find the required table and then add a checkbox field. My next move is to open up a table that I have password protected!

For information, the adapted code now looks like this:

Dim db As DAO.Database
Set db = OpenDatabase("c:\db1")

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

Set tdf = db.TableDefs("tblField")
Set fld = tdf.CreateField("CheckBoxField", dbBoolean)
tdf.Fields.Append fld

fld.Properties.Append fld.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))

db.Close
Set db = Nothing

 
Glad I could help.

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top