Microsoft KB Archive/280372

= How to fill a list box or a combo box with database object names =

Article ID: 280372

Article Last Modified on 3/26/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q280372



Advanced: Requires expert coding, interoperability, and multiuser skills.

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

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



For a Microsoft Access 97 version of this article, see 124344.



SUMMARY
This article shows you how to use the new AddItem method in Microsoft Access to fill a list box or a combo box with the names of database objects.



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 fill a list box or combo box with database object names:  Open the sample database Northwind.mdb. Create a new form in Design view.  Add a list box control, and then set the following properties:   Listbox -  Name: listObjects RowSourceType: Value List Column Count: 2 Column Widths: .7&quot;; 1.5&quot;   Add the following code to the form's OnLoad event: Private Sub Form_Load Dim accObject As Access.AccessObject 'Fill with Tables For Each accObject In CurrentData.AllTables Me.listObjects.AddItem &quot;TABLE;&quot; & accObject.Name Next 'If currently opened file is an Access database (mdb), then fill 'with queries. 'Otherwise, if it is an Access project (adp), fill with views, 'stored procedures, database diagrams, and functions. If CurrentProject.ProjectType = acMDB Then For Each accObject In CurrentData.AllQueries Me.listObjects.AddItem &quot;QUERY;&quot; & accObject.Name Next Else For Each accObject In CurrentData.AllViews Me.listObjects.AddItem &quot;VIEW;&quot; & accObject.Name Next For Each accObject In CurrentData.AllStoredProcedures Me.listObjects.AddItem &quot;PROCEDURE;&quot; & accObject.Name Next For Each accObject In CurrentData.AllDatabaseDiagrams Me.listObjects.AddItem &quot;DIAGRAM;&quot; & accObject.Name Next For Each accObject In CurrentData.AllFunctions Me.listObjects.AddItem &quot;FUNCTION;&quot; & accObject.Name Next End If   'Fill list with forms. For Each accObject In CurrentProject.AllForms Me.listObjects.AddItem &quot;FORM;&quot; & accObject.Name Next 'Fill list with reports. For Each accObject In CurrentProject.AllReports Me.listObjects.AddItem &quot;REPORT;&quot; & accObject.Name Next 'Fill list with data access pages. For Each accObject In CurrentProject.AllDataAccessPages Me.listObjects.AddItem &quot;PAGE;&quot; & accObject.Name Next 'Fill list with macros. For Each accObject In CurrentProject.AllMacros Me.listObjects.AddItem &quot;MACRO;&quot; & accObject.Name Next 'Fill list with modules. For Each accObject In CurrentProject.AllModules Me.listObjects.AddItem &quot;MODULE;&quot; & accObject.Name Next End Sub  Save the form, and then close it.</li> Open the form in Form view.</li></ol>

Note that the list box contains two columns. The first column contains the object type, such as table, query, form, and so on. The second column contains the object name.

Additional query words: OfficeKBHowTo inf listbox combobox boxes ACC2002

Keywords: kbprogramming kbcode kbhowto KB280372

-

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

© Microsoft Corporation. All rights reserved.