Queries in a Dropdown

G

Guest

Hey

I was wondering if there is a way to have the titles of the queries appear in a dropdown box, and then run a command button/report from the selection of the query. I tried the following code but it gives me every report, query, table, etc etc in my dropdown box. Is there a way to pick which queries I want in my dropdown? Thank you very much

Set the combo box Row Source Type property to Table/Query
Set the Rowsource to

SELECT MSysObjects.Name FROM MSysObjects WHER
(((Left([Name],1))<>"~") AND ((MSysObjects.Type)=5)) ORDER B
MSysObjects.Name

Set the bound column to 1
Set the ColumnWidths property to 1
Set the LimitTo List to Yes
Set the AutoExpand to Yes

Then, if you wanted to run any one particular query, based upon i
being selected in this combo box, code the AfteUpdate event
DoCmd.OpenQuery Me!ComboNam
 
G

Graham R Seach

Matt,

There's no way the query you used can return every report, query and table.
Specifying Type=5 filters it to return only query names. Check again!

SELECT [Name] FROM MSysObjects
WHERE [Type] = 5
ORDER BY [Name]

As for running the selected query, this code will do it:
Private Sub cboMyCombo_AfterUpdate()
If Not IsNull(Me!cboMyCombo) Then
CurrentDb.Execute Me!cboMyCombo.Value, dbFailOnError
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Matt said:
Hey,

I was wondering if there is a way to have the titles of the
queries appear in a dropdown box, and then run a command button/report from
the selection of the query. I tried the following code but it gives me
every report, query, table, etc etc in my dropdown box. Is there a way to
pick which queries I want in my dropdown? Thank you very much.
Set the combo box Row Source Type property to Table/Query.
Set the Rowsource to:

SELECT MSysObjects.Name FROM MSysObjects WHERE
(((Left([Name],1))<>"~") AND ((MSysObjects.Type)=5)) ORDER BY
MSysObjects.Name;

Set the bound column to 1.
Set the ColumnWidths property to 1"
Set the LimitTo List to Yes.
Set the AutoExpand to Yes.

Then, if you wanted to run any one particular query, based upon it
being selected in this combo box, code the AfteUpdate event:
DoCmd.OpenQuery Me!ComboName
 
G

Guest

Thanks Graham, it came up with all the queries now. I was wondering if there is a way to be able to choose which queries I want in the drop down box instead of all of them. Thanks again

-Mat

----- Graham R Seach wrote: ----

Matt

There's no way the query you used can return every report, query and table
Specifying Type=5 filters it to return only query names. Check again

SELECT [Name] FROM MSysObject
WHERE [Type] =
ORDER BY [Name

As for running the selected query, this code will do it
Private Sub cboMyCombo_AfterUpdate(
If Not IsNull(Me!cboMyCombo) The
CurrentDb.Execute Me!cboMyCombo.Value, dbFailOnErro
End I
End Su

Regards
Graham R Seac
Microsoft Access MV
Sydney, Australi

Microsoft Access 2003 VBA Programmer's Referenc
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.htm


Matt said:
queries appear in a dropdown box, and then run a command button/report fro
the selection of the query. I tried the following code but it gives m
every report, query, table, etc etc in my dropdown box. Is there a way t
pick which queries I want in my dropdown? Thank you very much
Set the combo box Row Source Type property to Table/Query Set the Rowsource to
SELECT MSysObjects.Name FROM MSysObjects WHER
(((Left([Name] said:
Set the bound column to 1
Set the ColumnWidths property to 1
Set the LimitTo List to Yes
Set the AutoExpand to Yes
Then, if you wanted to run any one particular query, based upon i
being selected in this combo box, code the AfteUpdate event
DoCmd.OpenQuery Me!ComboNam
 
G

Graham R Seach

Matt,

You can filter it just the same as any query. The following example filters
the return to those queries whose names begin with "qry":
SELECT [Name] FROM MSysObjects
WHERE [Type] = 5 AND Left([Name], 3) = "qry"
ORDER BY [Name]

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Matt said:
Thanks Graham, it came up with all the queries now. I was wondering if
there is a way to be able to choose which queries I want in the drop down
box instead of all of them. Thanks again.
-Matt

----- Graham R Seach wrote: -----

Matt,

There's no way the query you used can return every report, query and table.
Specifying Type=5 filters it to return only query names. Check again!

SELECT [Name] FROM MSysObjects
WHERE [Type] = 5
ORDER BY [Name]

As for running the selected query, this code will do it:
Private Sub cboMyCombo_AfterUpdate()
If Not IsNull(Me!cboMyCombo) Then
CurrentDb.Execute Me!cboMyCombo.Value, dbFailOnError
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Matt said:
the
queries appear in a dropdown box, and then run a command button/report from
the selection of the query. I tried the following code but it gives me
every report, query, table, etc etc in my dropdown box. Is there a way to
pick which queries I want in my dropdown? Thank you very much.
Set the combo box Row Source Type property to Table/Query. Set the Rowsource to:
SELECT MSysObjects.Name FROM MSysObjects WHERE
(((Left([Name] said:
Set the bound column to 1.
Set the ColumnWidths property to 1"
Set the LimitTo List to Yes.
Set the AutoExpand to Yes.
Then, if you wanted to run any one particular query, based
upon it
being selected in this combo box, code the AfteUpdate event:
DoCmd.OpenQuery Me!ComboName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top