Solved

Open Query From Combo Box In Form

Posted on 2004-09-04
2
212 Views
Last Modified: 2008-02-01
hi

i have querys named:

jan 01
feb 01
mar 01....  ranging all the way to dec 04

I have created a table called "Month (Stats)", with one field called "Month".
In this field i have all the same names as my querys jan 01, feb 02, mar 03, apr 04 etc....

I have also created a form with a combo box that lists all the options from this table.

Is it possible to run the correct query that corrosponds with the same month from this combo box.

also is it possible to have a command button next to this combo box that will open the selected query.

if this isnt clear enough im, sorry, but you guys will probably know what im on about.


Cheers!
0
Comment
Question by:danielgg
2 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 250 total points
ID: 11980446
You can, by doing this:
DoCmd.OpenQuery Me!MeComboBox

in the OnClick event of the command buttoon. This will run the query with the same name as whatever the combo box shows.

I wouldn't recommend though that you do it this way - you'd be better off designing just one query that returns data according to the month you select (it can do this by taking a criteria from the combo box) and just run that one query. That way, you can, for example, create one report that does everything you need rather than designing one report per query (or keep having to change report's record source).
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 11980448

set the row source of your combo box to

Select Distinct [Month] From [Month (stats)]

On the after update of the combo box
Private Sub ComboName_AfterUpdate()
Dim StrQuery as String
strQuery=Me.ComboName.Value
End Sub

on the click of the command button

Private Sub commandbutton_Click()
docmd.SetWarnings False
DoCmd.OpenQuery "" & strQuery &""

docmd.SetWarnings True

End Sub

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now