Microsoft KB Archive/210311

= ACC2000: How to Fill a Combo Box with Table Names =

Article ID: 210311

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210311



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article shows you how to create a sample user-defined Visual Basic for Applications function that you can use to fill a combo box or list box with the names of all the tables in the current 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. The following steps demonstrate how to create and use the sample ListAllTables function.  Start Microsoft Access and open the sample database Northwind.mdb. Insert a new module. On the Tools menu, click References, and select the following references if they are not already selected (checked):  Microsoft ActiveX Data Objects 2.1 Library Microsoft ADO Ext. 2.1 for DDL and Security

</li>  Type the following code in the module: Function ListTables(fld As Control, id As Long, row As Long, _                      col As Long, code As Integer) Dim cat As New ADOX.Catalog Dim tbl As ADOX.Table Static tbls(256) As String Static Entries As Integer Dim ReturnVal ReturnVal = Null

Select Case code Case acLBInitialize        ' Initialize database. cat.ActiveConnection = CurrentProject.Connection Entries = 0 For Each tbl In cat.Tables If tbl.Type = "TABLE" Then If tbl.Name <> "dtproperties" Then tbls(Entries) = tbl.Name Entries = Entries + 1 End If           End If         Next tbl ReturnVal = Entries Case acLBOpen              ' Open. ReturnVal = Timer       ' Unique ID number for control. Case acLBGetRowCount       ' Number of rows. ReturnVal = Entries Case acLBGetColumnCount    ' Number of columns. ReturnVal = 1 Case acLBGetColumnWidth    ' Column width. ReturnVal = -1          ' Use the default width. Case acLBGetValue          ' Get the data. ReturnVal = tbls(row) Case acLBEnd               ' End. For Entries = 0 To 256 tbls(Entries) = "" Next End Select ListTables = ReturnVal

End Function </li> On the File menu, click Save .</li> Create a blank new form that is not based on any table or query.</li> Add a combo box control to the form.</li> Set the RowSourceType property of the combo box to ListTables.</li> View the form in Form view. Note that the combo box lists all the tables in the current database.</li></ol>

Additional query words: tablenames

Keywords: kbhowto kbprogramming KB210311

-

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

© Microsoft Corporation. All rights reserved.