Microsoft Access Office VB VBA Help and Examples
           
             

Reading Database Object Properties in Code

Sometimes you will find that you want to access the property of an object in the database. This is not as straight forward as it sounds. In this example we want to read the Description of queries in the database.

Rather annoyingly Access objects properties don't exist for an object until that property has a value. The classic is the 'Description' property. To get round this when ready the property we have to assume it will error if the value has not been set.

The following function does just that.

Public Function GetQueryDescription(QueryName As String) As String
    Dim tmpstr As String
    tmpstr = ""
    Dim dbs As Database
    Dim qdf As QueryDef
    Set dbs = CurrentDb
    On Error Resume Next
    Set qdf = dbs.QueryDefs(QueryName)
    tmpstr = qdf.Properties("Description")
    If tmpstr = "" Then
        GetQueryDescription = "No Description or Invalid Query Name"
    Else
        GetQueryDescription = tmpstr
    End If
    Set qdf = Nothing
    Set dbs = Nothing
End Function

Just call the function from anywhere supplying it a query name and it will return either the description or a message telling you the query doesn't exist or there is no description.

 
HOME   SEARCH SITE   PRIVACY POLICY   CONTACT
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.