Querying the Query tab

harrisw

Registered User.
Local time
Today, 02:21
Joined
Mar 27, 2001
Messages
131
Is there a way I can display the contents of the query tab in a drop down list on a form so a user can simply click one to run the query. Rather than them having to see the database window.?
 
Add a combo box, mine is called cmbQuery and a command button, mine is cmdOpenQuery. Then add the code below on OnClick event of the command button.

Code:
Private Sub cmdOpenQuery_Click()
If Me.cmbQuery <> "" Then
    DoCmd.OpenQuery Me.cmbQuery
End If
End Sub

And this code on OnLoad event of the form.

Code:
Private Sub Form_Load()
Dim qdf As QueryDef, dbs As Database
Dim strList As String
Set dbs = CurrentDb
Me.cmbQuery.RowSourceType = "Value List"
For Each qdf In dbs.QueryDefs
    If Left(qdf.Name, 1) <> "~" Then
        strList = strList & qdf.Name & ";"
    End If
Next qdf
strList = Trim(strList)
strList = Left(strList, Len(strList) - 1)
Me.cmbQuery.RowSource = strList
End Sub
 
on the form load "Me.cmbQuery.RowSource = strList" gives an error saying the setting for this property is too long.

Any ideas
 

Users who are viewing this thread

Back
Top Bottom