This article was previously published under Q304274
This article has been archived. It is offered "as is" and will no longer be updated.
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.mdb).
This article shows you how to programmatically create a table and to specify the display control for a field. The sample code in this article creates the following table in the Northwind sample database:
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.
On the Help menu, point to Sample Databases, and then click Northwind Sample Database.
Create a new module, and then type or paste the following code:
Function AddYesNoField()'This sample function creates a table named tblYesNo.'It adds an AutoNumber field named ID and a yes/no'field named YesNo, with the display control as a check box.Dim db As DAO.DatabaseDim t As TableDefDim f1 As FieldDim f2 As FieldDim p As PropertySet db = CurrentDb'Create the table.Set t = db.CreateTableDef("tblYesNo")'Create the ID field.Set f1 = t.CreateField("ID", dbLong)'ID field is AutoNumber.f1.Attributes = dbAutoIncrFieldt.Fields.Append f1'Create the YesNo field.Set f2 = t.CreateField("YesNo", dbBoolean)t.Fields.Append f2db.TableDefs.Append tSet f2 = db.TableDefs("tblYesNo").Fields("YesNo")'Set the DisplayControl property to Check Box.Set p = f2.CreateProperty("DisplayControl", dbInteger, 106)f2.Properties.Append pSet db = NothingEnd Function
Save the module as modMakeTable.
In the Immediate Window type the following line, and then press ENTER:
On the File menu, click Close and Return to Microsoft Access.
Open the tblYesNo table.
Note that this table has two fields that have the properties that are listed in the "Summary" section of this article.
NOTE: In the code, 106 indicates a check box. You can set other controls with the following values: