OptionGroup value must drive Query Criteria

T

Tom

I am wondering if someone knows of an efficient way to execute a query with
different query criteria.

Here's what I have on a form (frmLogin):
- an optiongroup (values "1" or "2")
- 2 cascading combo boxes (cboState, cboCity)
- listbox with (currently) one value (which opens a query)

Here's the process (first, in general terms):
- user opens form
- user selects either value "1" or "2" from optiongroup
- user selects value from cboState, then value from cboCity
- user enters password
- if proper login criteria were entered, listbox becomes visible
- user clicks on value in listbox... which opens Query1

Additional Info:
- Query1's SQL code is listed below (between ***s)
- based on the values in cboState and cboCity it pulls the appropriate
records

**************************************************
SELECT Table1.Region, Table1.State, Table1.City
FROM Table1
WHERE (((Table1.State)=[Forms]![frmLogin].[cboState]) AND
((Table1.City)=[Forms]![frmLogin].[cboCity]))
ORDER BY Table1.Region, Table1.State, Table1.City;
**************************************************


.... everything works fine thus far.


Okay, here's the "twist"...
- only when value "1" is selected in the optiongroup, I will find matching
records
- if, however, value "2" is selected no records are found... that's because
I use dymanic rowsources for populating the cboState and cboCity
- and there are no records that would match the cboState and cboCity values
in Table1; again if optiongroup = "2"

.... and again that's fine.



Here's what I need to achieve:

1. If Optiongroup value = "1"
- execute Query1 as is when value "Query1" is clicked on listbox

2. If Optiongroup value = "2"
- do not execute Query1 with the cboState and cboCity criteria (as listed in
the SQL code above)
- instead, use another field (e.g. Textfield1) in the query as its
underlying criteria
- essentially, I need to implement a CASE statement that includes the
following (pseudo code)




If OptionGroup = "1"

'Execute process as outlined above

Else
Select Case cboCity = "United States"
DoCmd.OpenQuery1
where Textfield1 = "A" or "B" or "C"

Select Case cboCity = "Westcoast"
DoCmd.OpenQuery1
where Textfield1 = "A"

Select Case cboCity = "Central US"
DoCmd.OpenQuery1
where Textfield1 = "B"

Select Case cboCity = "MidAtlantic"
DoCmd.OpenQuery1
where Textfield1 = "C"
EndSelect
End If


BTW, when optiongroup value = "2" is selected, the cboState contains only
one value (that's why there's no need to
include it). However, cboCity has different values (e.g. "United States",
"Westcoast", "MidAtlantic").


Quick recap:
- depending on optiongroup value (1 or 2) I need to use different query
criteria
- if optiongroup = 1, I will use values in cboState (for field "State") and
cboCity (for field "City") as query criteria in Query1
- if optiongroup = 2, I cannot use the values in cboState and cboCity as
query criteria for "State" & "City"). Instead I must execute the query
using only cboCity... but now it must be the criteria for field
"Textfield1".

Any ideas as to how this can be achieved???

Thanks in advance!
Tom
 

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