Running a query and setting that value base on another combo box

D

Dom

Hi, I have a Form called Form1 and I have two combo boxs named combo1 and
combo2. Combo1 looks up the name of a person and displays it. I would like
to combo2 box to display the value of one of the 5 different qeurys base on
the value selected in combo1.

I was trying something like this and am not sure what to do to make the
query run.

Combo1_Click()
If Me.Form1.Value = "Jim" Then
//need help to run the first query name query1 to display in combo2

Else

Me.Form1.Value = "Fred" Then
//need help to run the second query name query2 to display in combo2

.....and so on


Not sure what I need to do to run the query name I selected or how to get
it to display in combo2

Thank you ahead of time
 
J

JConsulting

Hello Dom

How about a select Case.

Combo1_AfterUpdate()
select case me.combo1
Case "Jim"
me.combo2 = "Query1" <-----Not sure why you need a combo here...a simple
textbox would work
Docmd.openquery "Query1"
Case "Fred"
me.combo2 = "Query2"
Docmd.openquery "Query1"
<<Continue with however many cases you have>>
end select

An easier way would be to add the query name itself to the rowsource or
Combo1 then you could execute it directly when you selected it.

J
 
D

Dom

Thanks J,

Not sure what I did wrong but I didn't combo2 to display any values at all
so I don't think it work correctly or I did something wrong. What I am try
to do is select a person name and then take that value and run a query or
input that value into the query to get a list of all the projects that
person is working on. Once I get that I will then use the Click funtion to
open that record for the project.

If you think there is a better way to do this I am all ears.

Thanks
 
J

John W. Vinson

Thanks J,

Not sure what I did wrong but I didn't combo2 to display any values at all
so I don't think it work correctly or I did something wrong. What I am try
to do is select a person name and then take that value and run a query or
input that value into the query to get a list of all the projects that
person is working on. Once I get that I will then use the Click funtion to
open that record for the project.

You don't need to "run" another query at all.

Instead, base Combo2 on a Query selecting the projects belonging to the person
selected in Combo1. To do so use

[Forms]![YourFormName]![Combo1]

as a criterion on the person's ID field in the query.

You'll need to Requery Combo2 in the AfterUpdate event of Combo1, but there is
no need to "run" or open any query.

John W. Vinson [MVP]
 

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