John said:
Thanks Dirk That helps,
But now that I can refer to a query in my database window
how do I refer to it's "Description" property and/or set the
description if it doesn't exist. I've figured out how to do it for
Forms & Reports but...
Again the help file seems rather limited on this issue or
I am not able to understand it. Probably the latter.
"Description" is a special property for the QueryDef that may or may not
exist, depending on whether it has been created by Access (or by you)
yet. It can be accessed by name through the querydef's Properties
collection, but unfortunately, if you try that when the Description
property hasn't been created, an error will be raised. You might use
code something like this to deal with that:
'---- start of code ----
Sub DemoReadQueryDefDescription()
On Error GoTo Err_Handler
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strDescription
Set db = CurrentDb
Set qdf = db.QueryDefs("MyQueryName")
strDescription = qdf.Properties("Description")
Debug.Print strDescription
' ... or do whatever you want ...
' ...
Exit_Point:
Exit Sub
Err_Handler:
If Err.Number = 3270 Then
' property not found; don't worry about it
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If
End Sub
'---- end of code ----
If you want to set the property, again you have to trap the error if the
property doesn't exist, but instead of simply ignoring the fact you have
to create the property so that you can go back and set its value.
'---- start of code ----
Sub DemoSetQueryDefDescription()
On Error GoTo Err_Handler
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strDescription
Set db = CurrentDb
Set qdf = db.QueryDefs("MyQueryName")
qdf.Properties("Description") = "This is a querydef I'm testing."
' ...
Exit_Point:
Exit Sub
Err_Handler:
If Err.Number = 3270 Then
' property not found; create it.
qdf.Properties.Append _
qdf.CreateProperty("Description", dbText, " ")
Resume ' Go back and set the desired value.
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If
End Sub
'---- end of code ----
Note: the above is all air code, but between that and the examples in
the help you should be able to do what you want.