Passing combobox selection to query

  • Thread starter szag via AccessMonster.com
  • Start date
S

szag via AccessMonster.com

I have a query that has a "Job#" field in it. I want to be able to have
different criteria for the "Job#" depending on which combox box the user is
using within the app. Not a big VBA person but I assume there must be a way
to assign a criteria to a field in a query through VBA. Any help?
 
K

KARL DEWEY

No VBA, jusr SQL --
WHERE YourField = [Forms]![YourFormName]![YourCombo]

The form must be open and selection made before query is run and while it is
running.
 
S

szag via AccessMonster.com

Karl the problem is I have a different form with a different combo that I
want to use for this same query/criteria. I don't want to have 2 identical
queries with the only thing different being the criteria if there is another
way to assign the criteria in an event. does this make sense?

KARL said:
No VBA, jusr SQL --
WHERE YourField = [Forms]![YourFormName]![YourCombo]

The form must be open and selection made before query is run and while it is
running.
I have a query that has a "Job#" field in it. I want to be able to have
different criteria for the "Job#" depending on which combox box the user is
using within the app. Not a big VBA person but I assume there must be a way
to assign a criteria to a field in a query through VBA. Any help?
 
K

KARL DEWEY

The combo does not need to be in the same form as you are going to view.
Sequence --
Open form 1
Select criteria, leave form open
Open form 2
It displays your data. No need for event.

--
Build a little, test a little.


szag via AccessMonster.com said:
Karl the problem is I have a different form with a different combo that I
want to use for this same query/criteria. I don't want to have 2 identical
queries with the only thing different being the criteria if there is another
way to assign the criteria in an event. does this make sense?

KARL said:
No VBA, jusr SQL --
WHERE YourField = [Forms]![YourFormName]![YourCombo]

The form must be open and selection made before query is run and while it is
running.
I have a query that has a "Job#" field in it. I want to be able to have
different criteria for the "Job#" depending on which combox box the user is
using within the app. Not a big VBA person but I assume there must be a way
to assign a criteria to a field in a query through VBA. Any help?

--



.
 
S

szag via AccessMonster.com

Sorry if this is frustrating but maybe I didn't explain right:

I have a query that has as within its criteria the value of ComboBox1 from
Form 1. However I need this same query to use the criteria from ComboBox2
from form2 when ComboBox2 is updated. It needs to change depending on which
ComboBox is being updated. I don't want to write two queries that are exactly
the same except for one uses the criteria from ComboBox1 and one uses the
criteria from ComboBox2.

KARL said:
The combo does not need to be in the same form as you are going to view.
Sequence --
Open form 1
Select criteria, leave form open
Open form 2
It displays your data. No need for event.
Karl the problem is I have a different form with a different combo that I
want to use for this same query/criteria. I don't want to have 2 identical
[quoted text clipped - 11 lines]
 
K

KARL DEWEY

I was wrong on one point in that each combo must have event to set the other
combo to null and open correct form for viewing or refresh if already open.

I looked back and see that I omitted part of the criteria --
WHERE YourField = [Forms]![YourForm1]![YourCombo1] OR
[Forms]![YourForm2]![YourCombo2]

The query will ignore the combo that is set to null.

--
Build a little, test a little.


szag via AccessMonster.com said:
Sorry if this is frustrating but maybe I didn't explain right:

I have a query that has as within its criteria the value of ComboBox1 from
Form 1. However I need this same query to use the criteria from ComboBox2
from form2 when ComboBox2 is updated. It needs to change depending on which
ComboBox is being updated. I don't want to write two queries that are exactly
the same except for one uses the criteria from ComboBox1 and one uses the
criteria from ComboBox2.

KARL said:
The combo does not need to be in the same form as you are going to view.
Sequence --
Open form 1
Select criteria, leave form open
Open form 2
It displays your data. No need for event.
Karl the problem is I have a different form with a different combo that I
want to use for this same query/criteria. I don't want to have 2 identical
[quoted text clipped - 11 lines]
using within the app. Not a big VBA person but I assume there must be a way
to assign a criteria to a field in a query through VBA. Any help?

--



.
 
S

szag via AccessMonster.com

I think I got it! Dumb question but this will not affect other users in the
files at the same time will it?

KARL said:
I was wrong on one point in that each combo must have event to set the other
combo to null and open correct form for viewing or refresh if already open.

I looked back and see that I omitted part of the criteria --
WHERE YourField = [Forms]![YourForm1]![YourCombo1] OR
[Forms]![YourForm2]![YourCombo2]

The query will ignore the combo that is set to null.
Sorry if this is frustrating but maybe I didn't explain right:
[quoted text clipped - 17 lines]
 
S

szag via AccessMonster.com

Karl -

I have messed with this for a while now and can get it to work. I have two
different tabs (in a tab control) that have basically the same combo box
which is a "Job#". There is a report button next to each of the combo box's
that will run the same report. So if someone chose Job# ABC in tab 1 then
navigated over to tab 2 and chose Job # 123 then clicks the report button on
next to job# 123 the query criteria for "Job#" should use 123. however if
they went back to tab 1 and hit the report button next to Job ABC then the
query criteria for job# should use ABC.

So I want an event to fire off when the report button on tab 1 is clicked
that would have the report use the combo box in tab 1 the criteria and vice
versa. I can't seem to find the right code for the on click event.


KARL said:
I was wrong on one point in that each combo must have event to set the other
combo to null and open correct form for viewing or refresh if already open.

I looked back and see that I omitted part of the criteria --
WHERE YourField = [Forms]![YourForm1]![YourCombo1] OR
[Forms]![YourForm2]![YourCombo2]

The query will ignore the combo that is set to null.
Sorry if this is frustrating but maybe I didn't explain right:
[quoted text clipped - 17 lines]
 

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