473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting a parameter for a report based on a query

3 New Member
Hi all,

I'm facing an issue with Access that I haven't been able to find a solution for, despite hours of googling, so I hope someone here can help!

I've got a report - rptClientsByCou ntry - which is based on a query - qryClientsByCou ntry - that takes a parameter, myCountry, to filter the results. I need to be able to generate this report depending on the user's choice of country, preferably from a drop-down list.

Leaving aside for a minute the form part, I can't figure out how to pass a string to the report such that it accepts it as the parameter to the underlying query. Psuedo code would be:

sub command_click()

get current value of country drop down

set parameter myCountry on report

DoCmd.OpenRepor t "rptClientsByCo untry", acViewPreview

end sub

Can this be done? Or must I resort to setting the Where condition on the DoCmd.OpenRepor t?

Thanks in advance!
Jun 6 '07 #1
12 10844
maxamis4
295 Recognized Expert Contributor
It works just like a form

Expand|Select|Wrap|Line Numbers
  1.  
  2.     stDocName = "frm Name"
  3.  
  4.     stLinkCriteria = "[Report Criteria]=" & Me![form criteria]
  5.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  6.  
Jun 6 '07 #2
jamjar
50 New Member
It works just like a form

Expand|Select|Wrap|Line Numbers
  1.  
  2.     stDocName = "frm Name"
  3.  
  4.     stLinkCriteria = "[Report Criteria]=" & Me![form criteria]
  5.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  6.  
This method implies you get rid of the parameters per se.
You can pass parameters to the query in code, but I haven't figured out how to use these to run a Select query. For an action query something like this works:
Expand|Select|Wrap|Line Numbers
  1.   Dim qdf As QueryDef
  2.     Set qdf = CurrentDb.QueryDefs("yourQuery")
  3.     qdf.Parameters("myCountry").Value = Me.cmbCountry
  4.     qdf.Execute
  5.     qdf.Close
  6.     Set qdf = Nothing
  7.  
but if you try to Execute a select query it doesn't work. Ditto if you replace the execute with DoCmd.OpenRepor t you still receive a prompt for the parameter.
So like karanj I'm curious if anyone knows if/how you can pass a parameter to a select query so the user does not receive the prompt?

James
Jun 6 '07 #3
karanj
3 New Member
This method implies you get rid of the parameters per se.
...
if you replace the execute with DoCmd.OpenRepor t you still receive a prompt for the parameter.
So like karanj I'm curious if anyone knows if/how you can pass a parameter to a select query so the user does not receive the prompt?
Yep, exactly - this kind of basic modularisation would be very helpful! The "official" solution that I've found however is a little disheartening - see this article on the office.microsof t.com site. Surely that means that the query-report-form will effectively be coupled quite tightly?
Jun 7 '07 #4
karanj
3 New Member
It works just like a form

Expand|Select|Wrap|Line Numbers
  1.  
  2.     stDocName = "frm Name"
  3.  
  4.     stLinkCriteria = "[Report Criteria]=" & Me![form criteria]
  5.     DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  6.  
here effectively the form has to "know" the table/sql - I'd prefer to avoid this if possible so that the queries can be built by one person and the form/report by another. This seems to me something rather straightforward ...
Jun 7 '07 #5
jamjar
50 New Member
Yep, exactly - this kind of basic modularisation would be very helpful! The "official" solution that I've found however is a little disheartening - see this article on the office.microsof t.com site. Surely that means that the query-report-form will effectively be coupled quite tightly?
I would think so. The query would only be useful for the one form. I guess that means whatever form you may be starting with, you need to call the query's parameter form up before running the report based on it, and populate the parameter form with any selections that may already have been made in the originating form?

James
Jun 7 '07 #6
maxamis4
295 Recognized Expert Contributor
Let it stand that stlinkcriteria can be defined to what ever you want

here is an example

Expand|Select|Wrap|Line Numbers
  1.        stLinkCriteria = "[fID]=" & Me![fID]
  2.  
as well you could use a recordset
Jun 7 '07 #7
jamjar
50 New Member
Let it stand that stlinkcriteria can be defined to what ever you want

here is an example

Expand|Select|Wrap|Line Numbers
  1.        stLinkCriteria = "[fID]=" & Me![fID]
  2.  
Agreed.
There have been times when I have wished to be able to use parameters instead, but I can't remember a good example.
Jun 8 '07 #8
cfs
1 New Member
One sulution I think:

Create an invisible text-field in the active form (assuming you use a form to invoke the VBA-code, or have an active form that stays open). Use the VBA-code to write the desired parameter to the text-field (be sure to to this the right place regarding loops etc).

In the query, assign the parameter in the query to the invisible text-field. As you selection changes, so does the text-field, and the query based upon it shoul return the right results. at least this worked for me :)
Mar 17 '08 #9
truthlover
107 New Member
It works just like a form

Expand|Select|Wrap|Line Numbers
  1.  
  2. stDocName = "frm Name"
  3.  
  4. stLinkCriteria = "[Report Criteria]=" & Me![form criteria]
  5. DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  6.  
What am I doing wrong? This is my modification of the code, but I'm getting a "Compile Error: Variable not defined" for both the stDocName and stLinkCriteria.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintSelected_Click()
  2.     stDocName = "rpt_SurveyWorkOrder"
  3.  
  4.         stLinkCriteria = "[tbl_SurveyWorkOrder.SurveyWorkOrderID]=" _
  5.         & Me![tbl_SurveyWorkOrder.SurveyWorkOrderID]
  6.         DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  7. End Sub
Sorry if this is a dumb question, I'm only just learning VBA

Thanks!
May 22 '08 #10

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

Similar topics

2
4893
by: MJ | last post by:
Hi, I'm hoping this is relatively easy. I have a report based on a query - when you run the report, a form opens up and you are prompted for a date range. These are combo boxes (ie. January 2003, February 2003, etc). The combo boxes display the date field but the field that is actually sent back to the query is the corresponding identifier (ie. 1 for January 2003, 2 for February 2003) etc.
1
1938
by: MJ | last post by:
I'm not following... where do I put that? I put a textbox on my report and put the following property for it: =!!.Value This displays 1 (for January 2003). How do I get it to display January 2003 instead of 1? Thanks!
4
5729
by: Andy Davis | last post by:
I have developed a number of reports that are based on parameter queries where the user enters criteria such as a date range and a sales rep say. I want to be able to show a graphical picture in the form of a bar chart based on the data within the report. Can I do this as when I have tried to insert a chart on the report it displays an error saying that it doeds not recognise the parameter criteria. Am I right to assume that maybe a chart...
6
4480
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor have I been able to adapt other people's solutions/tips to fit what I need. If anyone could please help me with the following it would be really appreciated, thank you! I need to generate a Report (say: repCrossTab) that grabs it's data from the...
5
5306
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the user prompted for them). Based on a Microsoft page (http://support.microsoft.com/kb/287437), I tried the following approach: Private Sub Report_Open(Cancel As Integer) Dim sql As String
1
5078
by: waltnixon | last post by:
I've got an MS Access query which runs fine when double clicked and returns all of the rows in a test database I'm building. I've set up a multi group report based on the query. I immediately began getting the "Enter Parameter Value" dialog and it was asking for the query by its name "sel_report_data" whenever I tried to run or preview the report. To troubleshoot the problem, I selected the query in the database window, hit the "New...
2
1540
by: PotatoChip | last post by:
I am working in Access 2002 and I have been asked to create a form for a report based on a paramter query so that the user selects the department from a drop down list on the form, query runs and voila opens your report. Now, I have successfully done this, following the steps in a How-to I got off Microsoft's website, with just a form and a query. When I follow their instructions for the query-form-report, I get the form to open, select my...
1
1625
by: HSXWillH | last post by:
I have looked for some help on this and this article/thread was as close to what I was looking for as I could find. http://bytes.com/forum/thread603918-Null+Parameter+Query.html My only question is the end of the article talks about subforms and such and I don't think that's what I'm looking for exactly. My question is this: I have a query named Final_Results with the following fields: Position, E_Year, E_State, E_Type,...
25
4460
by: DanicaDear | last post by:
I am trying my hand at my first ever Access report. It is based on a two parameter query (start date, end date). When I use the report wizard and click "view report" the report prompts me for the two queries. Great! However, when I close it and re-run the report, it prompts me for a third parameter: HOTSTICK_FAILURE.DATE_ENTERED. The first half is a table name; the second half is a table field name. The query this report is based off...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.