473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Query design - How to design one query which can use different inputs

91
Hello,

Scenario:
I have list of policies for different countries. What I have done so far is that I have designed a query for each country which will pull out the policies for that country. The report is bases on this query. However, this way I am creating lot of queries.

What I want to do is design a query (and therefore the report) so that I can pull out the policies for a country by simply selecting a name from a drop down.

Tables and Fields are as below:

Table[Country]
CountryID
CountryName

Table[Policy]
PolicyID
CountryID
PolicyDetails

Could you please advise if this is possible and if yes, how to achieve this?

Thanks,
SG
Apr 13 '12 #1
13 1373
TheSmileyCoder
2,322 Expert Mod 2GB
Yes, that is quite easy.

You should design your report as you normally would, except you do not apply a filter on the country ID. Then you pass(and apply) the filter when you open the report.

Lets imagine you have a combobox in which you have selected your country, lets call it cmb_SelectCountry. You can now choose to either use the AfterUpdate event or make a button with code like so:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_PrintReport()
  2.   If IsNull(Me.cmb_SelectCountry) then
  3.     Msgbox "No country selected"
  4.     Exit Sub
  5.   End If
  6.  
  7.   docmd.OpenReport "rep_MyReportName",acViewPreview,,"ID_Country=" & me.cmb_SelectCountry,acDialog
  8. End Sub
Apr 13 '12 #2
sg2808
91
Thanks SmileyCoder.

Sorry,I am almost zero in VB coding :-(.

The way I am doing things are:

Step 1 - I am building the query first using Query Design. In the Criteria field, I am using the Country name for which I want the policies.
Step 2 - After saving the query, I am using Report Wizard based on the saved query to generate the report.

So, I am not using and Combobox at the moment (just using the Criteria in the Query design).

Given my situation, could you please walk me through how do I achive my objective?

Many thanks,
SG
Apr 13 '12 #3
Mihail
759 512MB
In your query, in field CountryName, in the Criteria row write this: Country ?
Run the query, answer to question, and let me know if this help you.

Cheers

PS: Open the report too
Apr 14 '12 #4
sg2808
91
Thanks Mihail for your response. I tried what you suggested.

On hitting the run button, there is no question, it just shows a blank datasheet.

The field in the Criteria changes to [Like "Country ?"] after running the query.

Any further suggestion please.
Apr 16 '12 #5
sg2808
91
Hi Mihail,

Just to add, I simply put a "?" in the criteria field and then I see this question box popping up. Now wondering, how do I put some additional text so that it shows in the message box that's popping up?

Many thanks,
SG
Apr 16 '12 #6
sg2808
91
OK, got this too.. I inserted this as [Country ?], and now I can see it working :-)
Apr 16 '12 #7
sg2808
91
Many thanks for your help Mihail.
Apr 16 '12 #8
sg2808
91
Sorry to pepper with more questions.....

I just want to know that the solution that you have suggested above, how does it work when the table has more than 1 field?

For eg, in the table[Country], if there are more fields eg

[CountryID]
[CountryName]
[Region]
[etc..]

If I want to use the filter the information based on [Region] or any other field, will it still work?

Many thanks,
Apr 16 '12 #9
Mihail
759 512MB
Try it !
Apr 16 '12 #10
sg2808
91
:-) It works for multi fields and multi tables as well, thanks.

The problem that I face is that the entry has to be same as that in the table and if the list is long, then it is not great to have everything in the pop- up.

Is there a way that I can show the available options using a drop down so that it is easier for any user to select and generate the report they want?

Thanks,
Apr 16 '12 #11
Mihail
759 512MB
Yes it is.
See Smiley's solution.
Apr 16 '12 #12
sg2808
91
Many thanks. I can do this but I need little bit of hand holding here to implement Smiley's solution.

Can anyone walk me through the steps that I need to take?

Thanks.
Apr 16 '12 #13
sg2808
91
I tried the following as suggested by one of the gurus:

1. Create a blank form and add the Combobox/Dropdown control on it.
2. Follow the Wizard to display the names of the countries for the selection.
3. Create a new query (or modify one of the existing ones) to display all the policy data.
4. For the country criteria, enter a reference to the dropdown control on the form. It should look something like this:

Forms!FormName.ControlName

5. Create a new report (or use the same one based on the query you modified) based on the new query.
6. Add a button on the form and follow the Wizard to "open the report."

To test it, open the form and select a country from the dropdown, then click on the button.

This worked for me !
Apr 17 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
4
by: PC Datasheet | last post by:
A query based on TblEmployee shows TblEmployee in the query window. Is there a way in design view to change this query to self join T1 and T2 on EmployeeID or does it have to be typed in in SQL...
2
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some...
3
by: faceman28208 | last post by:
Over the past few years I have consulted on six large projects that all independently arrived at the same moronic design desision: The use of SQL query classes. No, I don't mean a class...
1
by: santaferubber | last post by:
The first query returns me the results from multiple databases, the second does the same thing except it puts the result into a #temp table? Could someone please show me an example of this using...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
5
by: manjubhashini19583 | last post by:
Sir, how to write select query and insert query at the same time. I have one database that db having six field. waiting for your reply. thanking you
1
by: dbarmer | last post by:
I have a unix database system that hold three tables, 254, 255, 256, and all are linked together by WO, CUST NO, LOC NO. This is for Unix Program Purposes Only. Duplication here is by design. So...
3
by: robin1983 | last post by:
HI all, how are you ? i need help from you people. This time my problem is that i m running a query inside another query. But, the result that i got is something not exactly what i want. and one...
1
by: alipark | last post by:
hi, I am fairly newb to mysql, so excuse my silly question. I am working on a vbmysql application for a warehouse. Here I am importing an excel sheet to mysql which has weekly status of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.