|
![]()
Displaying Database Objects in a Combo BoxFirstly, you can use a System table, MSysObjects, and use this as the RowSource for the combo box. To view the System Tables in your database, set View|Options|System Objects to 'Yes'. Half a dozen tables now appear in the tables tab, but do not amend them, or your database will very likely become corrupt. Add a new combo box to the form, and click on the ellipsis next to the RowSource property to open up a query grid. Add the MSysObjects table to the query grid, and then Double Click on the fields 'Type' and 'Name'. Enter a criteria for 'Type' of 1, and a criteria for 'Name' of Left([Name],4)<>"MSys" to ignore the system tables. Remove the tick from the 'Show' box for 'Type' so that the user doesn't see this column, and set it to sort Ascending on the 'Name'. Close the query grid and accept the changes. The SQL should look like:
This will only include native Access tables - to also include attached Access tables, you will need to have a criteria to include their type (which is 6). The second way is to use a value list that is calculated, by looping the relevant collection, when the combo box gets the focus. The main problem with using this method is that the RowSource is limited to 2048 characters, which obviously won't be enough if you have many Tables in the database. Add a combo box to the form, and change it's RowSourceType to 'Value List'. In the Combo Box's GotFocus event, have the following code:
The third way of displaying the required data is to use a user-defined function as the RowSourceType, leaving the RowSource blank. Below is an example of such a function:
Obviously, you can alter these to display the appropriate objects in the Combo/List Box by using the correct collection. Or alternatively, you could use an extra list box to allow the user to select the type of object, and then use that to select the correct object. You can download an Access 97 database that shows these 3 different methods here.
Copyright & Disclaimer | |||||||||||||||
| Last modified at 06/06/2006 14:54:06 | ||||||||||||||||