Solved

Open Query From Combo Box In Form

Posted on 2004-09-04
2
211 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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

14 Experts available now in Live!

Get 1:1 Help Now