Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to select one or many or all in a query ! 2

Status
Not open for further replies.

maverick

MIS
Apr 21, 1999
193
US
I have a report to print, but...<br>
I need to be able to select all records with TX., CA. or as many as I need at the time.<br>
I'm not sure how to do this...Query? criteria?<br>
Parameter subform? I'm blank on this...for some reason.<br>
<br>
I know in the query criteria you can put &quot; Like[Enter State]<br>
but you only get one choice!<br>
and it will ask you to enter state, but what if I want CA TX OR and tomorrow I will need just CA, and the next day I need all state. ????<br>
<br>
Thanks...
 
The criteria needs to be in the query that your report is based on. If you just want to do it manually, use &quot; in set()&quot; on your criteria line of your query in your state column. (Go in design view of your report and click on the Properties icon, then the Data tab then the Data Source property.) For example:<br>
in set (TX)<br>
in set (TX, OR, CA)<br>
in set (CA, TX)<br>
<br>
There's a complete article on how to do this through code with a listbox at <A HREF=" TARGET="_new"><br>
 
Also If you want the query to prompt you<br>
put this in the box with brackets around it.<br>
[Enter State]<br>
Where what is inside the brakets will show as the question asked.<br>
If you type &quot;TX&quot; then it will show Texas<br>
<br>
<br>

 
first of all;<br>
Thanks for replying !!!<br>
<br>
I knew this would be hard to explain;<br>
I need to create a report that I can select one, many or all of the states in a query column to avoid having to make more than one column with criteria that says [Enter State].<br>
<br>
I'm checking out the &quot;in set()&quot; idea now !<br>

 
Elizabeth ; is there any way I can get that report from you , it appears that site charges for access...<br>
<br>

 
Sorry! I get the magazine so apparently I've already paid for it. If they're charging for it I probobly shouldn't reporduce it in a public forum. If you can't get into this one, just let me know and I'll paraphrase for you.


 
I appreciate your honesty and Integrity !!!<br>
<br>
I've ordered the magazine... but they didn't guive me a password to enter the site, does that come with the magazine ?<br>
<br>
Thanks for your help, this one is kicking my butt !<br>
<br>
I am a Troubleshooter HW, SW, Networks ten years.., now Access, But this is tuff !<br>
<br>
It was time to get into programing anyway !<br>
<br>
ta,
 
So you want to pick mutiple states say &quot;give me items from Texas and Florida and California&quot;?<br>
but be able to change the number of states and and which states as you mentioned above in a Combo box or something?<br>
<br>
Or in other words have it build a SQL statement like<br>
....Where State = &quot;TX&quot; and &quot;CA&quot; and &quot;FL ....<br>
<br>
Is that what you want to do?
 
That sounds about right,<br>
have a form where I can enter into feilds,<br>
<br>
feild one; tx,ca,or<br>
feild two; Smith<br>
<br>
and get a report back that gives me all records with "tx,ca,or" in the state feild of that table that have the last name "smith"..<br>
<br>
and have an additional button on the same form that will give all records in the report..<br>
<br>
You guys are great, I never thought I would get good responses back !<br>
<br>
Thanks !
 
I would ask them to email the complete article to you, but the gist of it is:<br>
1. Create a report.<br>
2. Create a form with a list box and an Open Report button.<br>
3. Populate the list box with the choices using a query as the Row Source.<br>
4. Add code to the OnClick event of the button. The code dims variables (dim Forms!YourFormName!YourListBoxName as &quot;ctl&quot;), loops through each of the selected items in the list box, then opens the report. The crux is the loop and following 2 lines:<br>
<br>
If ctl.ItemsSelected.Count = 0 then<br>
' insert a message box asking user to select state, then exit)<br>
Else<br>
For each var in ctl.ItemsSelected<br>
temp = Chr(39) & ctl&gt;itemDate(var) & Chr(39) & &quot;,&quot;<br>
strCriteria = strCriteria & temp<br>
nextvar<br>
end if<br>
strCriteria = Left$(strCriteria, Len(strCriteria)-1)<br>
strCriteria = &quot;[strState] In (&quot; & strCriteria & &quot;)&quot;<br>
<br>
strState refers to the name of the state field in your table.<br>
Hope I haven't made any serious typos!<br>
<br>

 
Typo! &quot;&gt;&quot; should be &quot;.&quot; <br>
Also should have mentioned strCriteria is a parm in DoCmd.OpenReport
 
Ahhhh... another typo! &quot;ctl&gt;itemDate(var)&quot; should be &quot;ctl.ItemData(var)
 
Sorry, I shouldn't have made the assumption you had some familiarity with VBA. If not, you need to get some background first or get step-by-step instructuions, such as are in the (lengthy) IMA article. If you've bought a subscription, why don't you get in touch with them to see if they can help you with that.
 
Thank you all very much for your comments;<br>
<br>
I have always thought that most VBA programers in general over-complicate simple tasks..not to say you guys do !<br>
I have figured out a simple way to acomplish this task;<br>
<br>
Create a selection form with multiple combo boxes, as many as are needed for your choices, that show you the data your querying, <br>
Example; &quot;combobox1 is Unbound but named [state1]&quot; and so on,,,[State2] etc...<br>
<br>
Create a query that pulls the info you need for the report, in one of the columns in your query type the following:<br>
<br>
IIf(IsNull([Forms]![Selection frm]![state1]),True,IIf([tblPeople].[State] In ([Forms]![Selection frm]![state1],[Forms]![Selection frm]![state2],[Forms]![Selection frm]![state3],[Forms]![Selection frm]![state4],[Forms]![Selection frm]![state5]),True,False))<br>
<br>
it will label it Exp1 don't worry that will go away by it self!<br>
The SHOW check box should be clear!<br>
<br>
'the people table should be in your qurey'<br>
<br>
No code required ! just simple query criteria ...<br>
<br>
As I thought it could be done....<br>
<br>
Don't forget your print button on the selection form<br>
and to have the report pull from your new query..<br>
<br>
Thank you very much &quot;everyone&quot; who tried to help, this was very important to me !!!!<br>
<br>
Mav out,,<br>

 
I missed one thing;<br>
in the criteria column with the code typed above<br>
the criteria is True and the stuff typed above goes in the first row of that column..no check in show-box<br>
<br>
Thanks Guys !!!
 
I'm glad you found a method that works for you. Thank you for posting your solution! <br>
<br>
BTW, maybe one reason other people's solutions seem overcomplicated is that they have different criteria for solving a problem. For instance, one person may be most interested in simplifying the User Interface to make the app more palatable for the customer. Another might be most concerned with very robust error checking, as they won't be around if the user does something unexpected. Most professional programmers have at least a token interest in writing code that runs efficiently, and can be easily maintained. In some cases the goal is to do something quickly, using existing skills, because the problem is urgent. I think the best programmers try to optimize, considering all these things. <br>
<br>
And one of the great things about these forums is that you get to see a number of different approaches. Even when one person has posted a workable solution, you often see a second or even third approach posted. I love to see that.
 
Forgive me if I don't understand the question, but it seems to me that the kiss answer to this is just to use "OR" in the query criteria. I've used numerous criteria in a single column many times. The SQL would go something like WHERE table.state LIKE "CA" OR LIKE "OR" OR LIKE "FL", etc. You easily design a popup form and concatenate a SQL statement or filter string. If you were doing this in query design, you can use the OR directly in the criteria in a single column.<br>
<br>
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top