Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS ACCESS Retrieving "Table Description" Through Query

Tags:

vba

ms-access

I've been looking everywhere for a way of accessing a table's description (same one that appears when you right click a table>table properties) through a SELECT query.

I tried using MSysObjects but I can only retrieve the name of the table using that.

Is it possible to do this through a query or is VBA needed?

like image 421
BadgerBeaz Avatar asked May 15 '12 19:05

BadgerBeaz


People also ask

How do you add a description to a query in Access?

For a database object, click Properties on the View menu and enter the description text in the Description box. For tables or queries, you can also enter the description in the table's or query's property sheet.

How do you describe a table in Microsoft Access?

Answer. It consists of columns, and rows. In relational databases, and flat file databases, a table is a set of data elements (values) using a model of vertical columns (identifiable by name) and horizontal rows, the cell being the unit where a row and column intersect.

How do you analyze a table in Access?

In Microsoft Office Access 2003 or in Microsoft Access 2002, point to Analyze on the Tools menu, and then click Table. In Microsoft Office Access 2007 or a later version, click the Database Tools tab, and then click Analyze Table in the Analyze group.


2 Answers

As Remou says, you can't get it from a query (but you can include a function that returns it in a query). Here's another function:

Public Function GetTableDescr(stTableName As String) As String
On Error Resume Next
GetTableDescr = CurrentDb.TableDefs(stTableName).Properties("Description").Value
End Function

Here's a query that returns all the non-system tables, with their dates and descriptions (using the function above):

SELECT MSysObjects.Name, msysobjects.datecreate, msysobjects.dateupdate, GetTableDescr([Name]) AS Description
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "~*") AND((MSysObjects.Name) Not Like "MSys*") and ((MSysObjects.Type)=1));

Finally, you can do an almost identical function for queries. The trick I found is that you only return non-inherited descriptions, otherwise if a query has no description you get the description of the queried object:

Public Function GetQueryDescr(stQryName As String) As String
On Error Resume Next
If CurrentDb.QueryDefs(stQryName).Properties("Description").Inherited = False Then
    GetQueryDescr = CurrentDb.QueryDefs(stQryName).Properties("Description").Value
End If
End Function

The On Error Resume Next is necessary, because until the object has a description the property is null.

like image 117
Doug Glancy Avatar answered Oct 02 '22 19:10

Doug Glancy


You can get the description from the table schema or from TableDef properties, but I do not think a standard query will work.

Set rs = CurrentProject.Connection.OpenSchema(adSchemaTables, _
     Array(Empty, Empty, "Rules", Empty))
Debug.Print rs!Description
like image 32
Fionnuala Avatar answered Oct 02 '22 18:10

Fionnuala