This page was split off from my generic CM Page do to the number of examples provided.
Dim tempDatabase As Database Dim tempTableDef As TableDef ' Set a reference to the current database Set tempDatabase = CurrentDb For Each tempTableDef In tempDatabase.TableDefs Debug.Print tempTableDef.Name NextCareful, this also lists private tables starting with MSys that the user normally won't see.
Listing Forms and Reports
To list all forms in the database, whether open or closed, enumerate the Documents collection of the forms' Container object. You can then use the Name property of each individual Document object to return the name of a form.Great! But an example would be useful.
Dim tempDatabase As Database Dim xx ' I use a variant to simplify the code ' Set a reference to the current database Set tempDatabase = CurrentDb ' List all the available containers For Each tempContainer In tempDatabase.Containers Debug.Print tempContainer.Name Next tempContainer ' List all the documents in the specified container type ' (In this case, list all the forms) For Each xx In tempDatabase.Containers![Forms].Documents Debug.Print xx.Name Next xxThe code above returned the following containers
If you use this technique to access Tables, then you will see additional default tables and the Fields collection will not be available.
select Name, DateUpdate from MSysObjects where Type=-32768;Queries and tables are a little wierd because many are generated by the system. In order to limit the returned values to just those created by the designer, you should use code similar to the following.
select Name, DateUpdate from MSysObjects where Type=5 and Name not like "~*";
|Type||and Name not like|
Tools / Add-Ins / Linked Table ManagerHowever, on my system, the paths are so long that the useful data is missing. (No the window can not be enlarged and the data can not be copied to the clipboard .. I've checked.)
The solution uses MSysObjects. Just copy the following query to an sql editor and run it.
SELECT Name, ForeignName, Database FROM MSysObjects WHERE Database Is Not Null;
The fields are
|Name||Name (alias) in this database|
|ForeignName||Name in the remote database|
|Database||Path to the mdb file|
However, when it come to accessing this data via code, this is another poorly documented property!
The following is based on information from Field / Specifics and other help pages listed below.
Dim tempDatabase As Database Dim tempTableDef As TableDef Dim tempField As Field Dim xx ' Set a reference to the current database Set tempDatabase = CurrentDb For Each tempTableDef In tempDatabase.TableDefs Debug.Print tempTableDef.Name + " *********" For Each tempField In tempTableDef.Fields On Error GoTo ErrorHandler xx = tempField.Properties!Description ' This fails !!! Debug.Print tempField.Name & " " & xx ' Debug.Print tempField.Properties!Description ' This fails !!! ' Debug.Print tempField.Description ' This fails !!! Next tempField Next tempTableDef Exit Sub ' You must exit before the error handler ErrorHandler: xx = "aa" ' A null string would be better, "aa" is just for test Resume NextFrom the Description Property help
An object's description is displayed in the Description column in the Details view of the Database window.From the Property Object / Specifics help
If you create controls by dragging a field from the field list, Microsoft Access copies the field's Description property to the control's StatusBarText property.
Until you have set a Microsoft Access-defined property either in table Design view or from Visual Basic code, that property won't appear in the Properties collection. When you set these properties from Visual Basic, you should include error-handling code that checks to see if the property exists in the Properties collection, and creates and appends the property if it doesn't.This seems to also apply to reading these properties - You have to expect and catch errors. Unfortunately, the error processing is extremely slow! At least 10 times slower!
The 2 commented out lines in the code above were left there to demonstrate what does not work.
The Description is included when you select Tools / Analyze / Documenter.