I used your suggestion about using a form. It works fine. My form is
based on a table. My criteria is based on States. We have 6 states that
we are summing data on: AL, AZ, CO, FL, NM, TX. So in my States table
(Fields: State, StateAbrev, StateCode (all text fields)) I have 6
records, 1 for each state. So with the form open, I can navigate to the
state I want to get data for and then run my query.
The problem I'm having is that at times I want to get data on all states.
I was trying to enter another record in the States table to accomplish
this: State = All; StateAbrev = ALL; StateCode = *. I could not get this
to work.
I simplified the query into a single select query (eliminated all the
UNIONS) and changed the criteria to a parameter so it will ask me to enter
the state code. I've tried *, "*", Like *, Like "*", 0*, "0*", Like 0*,
Like "0*". Nothing seems to work--all of these combos returned a
recordset with 0 records (it will return a recordset with 1 record when I
enter an actuall state code--it should return a recordset with 1 record in
it but with balances for all states sumed). (the 0* combinations above
are because the StateCode field for each state is 4 numeric characters
(text field, remember) and the first 2 characters are 0's (zeros))
Is there some kind of wild card combination that I can enter into my
Table/Form record (or parameter) that will allow me to return all states?
Thanks again for all of your help,
Conan Kelly
Allen Browne said:
Try declaring your PARAMETERS on the first line of the query, i.e. before
the first SELECT.
With a normal query (not UNION), you can get Access to generate this line
for you by choosing Parameters on the Query menu. Then switch to SQL View
(View menu), and copy the example you see there.
An alternative would be to use a form where the user enters the values,
and then refer to that same location in each query, e.g.:
[Forms].[Form1].[Text0]
Conan Kelly said:
I'm going to try to create a UNION query that will sum balances from 16
other queries. In each of these queries is data for 2 states. I would
like to have the query to ask the user for which state they want data
only once at the begining of the query and then pass that parameter on
to each of the other queries in each part of the UNION query.
Is this possible? Please post some sample SQL text on how to do this.
I have no idea on where to begin. Can I have variables in SQL text that
I can assign a value to?