Microsoft KB Archive/304274

= ACC2002: How to Programmatically Specify the Display Control for a Field =

Article ID: 304274

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q304274



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).



SUMMARY
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:



MORE INFORMATION
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.

 Start Access. 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.Database Dim t As TableDef Dim f1 As Field Dim f2 As Field Dim p As Property

Set db = CurrentDb

'Create the table. Set t = db.CreateTableDef(&quot;tblYesNo&quot;)

'Create the ID field. Set f1 = t.CreateField(&quot;ID&quot;, dbLong)

'ID field is AutoNumber. f1.Attributes = dbAutoIncrField t.Fields.Append f1

'Create the YesNo field. Set f2 = t.CreateField(&quot;YesNo&quot;, dbBoolean) t.Fields.Append f2 db.TableDefs.Append t Set f2 = db.TableDefs(&quot;tblYesNo&quot;).Fields(&quot;YesNo&quot;)

'Set the DisplayControl property to Check Box. Set p = f2.CreateProperty(&quot;DisplayControl&quot;, dbInteger, 106) f2.Properties.Append p

Set db = Nothing End Function  Save the module as modMakeTable .  In the Immediate Window type the following line, and then press ENTER: ?AddYesNoField  On the File menu, click Close and Return to Microsoft Access.</li> Open the tblYesNo table.

Note that this table has two fields that have the properties that are listed in the &quot;Summary&quot; section of this article.</li></ol>

NOTE: In the code, 106 indicates a check box. You can set other controls with the following values:
 * 109 - Text Box
 * 110 - List Box
 * 111 - Combo Box

Additional query words: inf

Keywords: kbhowto KB304274

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.