How would I set that up? I would like to list all queries that start with
a
given prefix. Thanks in advance for your help.
Here are two approaches:
1) a simple query that provides just query names
(This has no prefix criteria, but that's simple enough to add):
SELECT Name, Type
FROM MSysObjects
WHERE ((MSysObjects.Type)=5);
2) this approach will fill a listbox with query Names *and* the Descriptions
that appear in the database window:
(Excluded: queries starting with "~" and "q_", as well as those designated
as system objects.)
Public Sub FillQueryList(lbo As ListBox)
' Fill listbox with list of queries AND their descriptions
' Modified from Access Developers Handbook (I think)
On Error GoTo ErrHandler
Dim db As dao.Database
Dim qdf As dao.QueryDef
Dim strList As String
Dim strDescription As String
Dim fSystemObj As Boolean
Dim fShowSystem As Boolean
fShowSystem = Application.GetOption("Show System Objects")
Set db = CurrentDb
db.QueryDefs.Refresh
For Each qdf In db.QueryDefs
'Check and see if this is a system object
fSystemObj = IsSystemObject(acQuery, qdf.Name)
' Skip query if its a system object
If fSystemObj Eqv False Then
strDescription = " "
' skip certain other queries
Select Case Left$(qdf.Name, 1)
Case "~"
' Don't include
Case "q"
If Mid$(qdf.Name, 2, 1) <> "_" Then
strList = strList & qdf.Name & "; "
On Error Resume Next
strDescription = qdf.Properties("Description")
On Error GoTo ErrHandler
strList = strList & strDescription & "; "
End If
Case Else
strList = strList & qdf.Name & "; "
On Error Resume Next
strDescription = qdf.Properties("Description")
On Error GoTo ErrHandler
strList = strList & strDescription & "; "
End Select
End If
Next qdf
lbo.RowSourceType = "Value List"
lbo.RowSource = strList
ExitHere:
Set qdf = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
' (not included) Call ErrorLog(mDocName & ": FillQueryList")
Resume ExitHere
End Sub
Private Function IsSystemObject(intType As Integer, ByVal strName As String,
_
Optional ByVal varAttribs As Variant) As Boolean
On Error GoTo ErrHandler
' Determine whether or not the object named 'strName' is
' an Access system object or not.
' Returns TRUE/FALSE
If IsMissing(varAttribs) Eqv True Then
varAttribs = 0
End If
If ((Left$(strName, 4) = "USys") Or (Left$(strName, 4) = "~sq_")) Eqv
True Then
IsSystemObject = True
Else
IsSystemObject = ((intType = acTable) And _
((varAttribs And dbSystemObject) <> 0))
End If
ExitHere:
Exit Function
ErrHandler:
'Call ErrorLog(mDocName & "/" & CurrentObjectName & ": IsSystemObject")
Resume ExitHere
End Function
HTH,