473,624 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Provide a value to a query prompt – while running a report

38 New Member
I built a query and use it in a report. The query has one parameter that must be satified at run time which is [Year_Id]. Rather than user type a value, I need to provide a value based on certain calculation which I intend to do when the report is open. I have the following code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. MsgBox "Now In Report_Open Sub"
  3. 'Do the calculation here
  4. 'Provide a value for Year_Id of the query prompt
  5. End Sub
What I need to know is how can I reference the [Year_Id] of the query and give it a value.

Greatly appreciate your help in advance.
Saleem
Feb 23 '08 #1
10 2306
salzan
38 New Member
Any ideas, anyone?
THank you,
Salzan
Feb 23 '08 #2
Scott Price
1,384 Recognized Expert Top Contributor
I doubt that doing this calculation in the On Open event of your report is going to work, since the query is 'queried' before the On Open event fires.

You'll have to work backward and do your calculation in the query itself, or in the On Click event of a button that opens the report.

What calculation are you attempting to perform?

Regards,
Scott
Feb 23 '08 #3
salzan
38 New Member
I know for fact that the query is not executed prior to Report_Open. I tested it by placing a MsgBox in the code which comes up first and then the query prompt follows as I step in through the code. I'm assuming there's a control/attribute associated with the query paramter. I need to find a way to access it and set its valur.
Salzan
Feb 23 '08 #4
Scott Price
1,384 Recognized Expert Top Contributor
If you are going to force a calculation, why not write it into the query itself?

Regards,
Scott
Feb 23 '08 #5
salzan
38 New Member
It's complicated. I have to process 3 files. collect the info that was recently entered. Determine the record date for the data. Read a 4th table which is a determines a valid fical year range and then produce the report for that year. I think it'll be easier if I can just findout how to set a value for a parameter in a query. Don't you think?
Salzan
Feb 23 '08 #6
Scott Price
1,384 Recognized Expert Top Contributor
In response to your question, I would say 'maybe'... I do not know of a way to satisfy the parameter value through code directly like you are wanting to do. It may be possible, but I doubt that it's very common, therefore you're not likely to find much about it on the internet, nor in MS help files. A parameter query is specifically constructed to require user participation, so therefore, attempting to short-cut this by background calculation is not likely to have very many proponents.

This MS article provides a possible work-around in that it involves creating a form to collect the user parameters. (btw you are right, something I didn't know, but is mentioned in the article is that the report On Open event fires before the RecordSource is queried).

You could possibly use this form to do the calculations you wish, simply opening it hidden, making it do the calculation and then closing it with the report.

Good luck!

Regards,
Scott
Feb 23 '08 #7
salzan
38 New Member
Thanks Scott. I'll check out the article and report back on my progress.
Feb 23 '08 #8
NeoPa
32,567 Recognized Expert Moderator MVP
I know for fact that the query is not executed prior to Report_Open. I tested it by placing a MsgBox in the code which comes up first and then the query prompt follows as I step in through the code. I'm assuming there's a control/attribute associated with the query paramter. I need to find a way to access it and set its valur.
Salzan
You're right Salzan. This is where the Help system suggests you add code to modify the RecordSource for a report.
However, unless you want to go to the trouble of :
  1. Getting the .SQL from the RecordSource.
  2. Doctoring it in code to apply whatever changes you would like.
  3. Setting the .RecordSource to the SQL string just created.
... then you'll have difficulty.
A QueryDef, run by the code, can have PARAMETERs passed to it, but this is not available (as far as I'm aware) when running a report BASED on a QueryDef.
Feb 28 '08 #9
NeoPa
32,567 Recognized Expert Moderator MVP
If it's possible (you're not too clear in your question), it would certainly be better simply to apply a filter. That is, if the change you want to apply is simply in the WHERE clause.
Feb 28 '08 #10

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

Similar topics

2
1701
by: seansan | last post by:
Hi, suppose I have one report that reports some data to me based on a functional area that I define. We have about 20 func_areas and every time the report is the same. Is there some way to have the report ask me (based on a query or something) what func_area I would like the report to be based on? ps. the report is based on a query so ultimately the selection has to be passed to the query.
1
4199
by: Steve | last post by:
I am using Access 2000 and I have a DB that is currently running four different queries from some Forms and subforms. These queries each have a date field that are seperate from each other that are from those said forms. Currently I have setup the criteria for these queries to prompt a user to enter a month # Query Field: Month() Criteria:
3
2730
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have reports at the plan (overall totals), department and division levels which have sorting and grouping implemented with this new
2
1630
by: HateSpam | last post by:
I have a paramter query that wants either of 2 date fields in a table to be before a certain date. Select * from tblExample where Date1 < or Date2 < When I open this query, it prompts me twice for dtCutoff. I've verified I'm using the same spelling and capitalization. Is there a way to make it only prompt once?
4
2332
by: Kathy | last post by:
When a report that has several prompts for values to be printed on the report is requested by certain users, they get prompted for the values twice. For some users, the prompts occur only once. The prompts are not associated with a query, they merely act as a way to add user-entered values to the report output. What kind of settings would cause only certain users to get double-prompted? Could the network configuration or how the users...
2
1515
by: starke1120 | last post by:
I have a query that has a prompt for date as Between And This database is hosted on a share drive. About half of my user's are ok with the report that has this query the other half when the prompt comes up for the first sections the box displays Enter Start Date - Format "MM/DD/YYYY:,2
1
3450
by: viral123 | last post by:
Hi all I am using Crystal report and I am running my report successfully for my query but I want to make my query for one specific date. I want to get the date value from the textbox value. My query small example is as follow: Select name from employee where date_of_birth = '01/01/1984'
6
6854
by: Phil Stanton | last post by:
I am running a query that calls a function used to format addresses depending on the width of a control on a report that shows that address. The same query is used as the RecordSource of lots of similar reports, but all with different sized Address text boxes. For the function to work, the report need to be open in design view, so that the Text Box Width can be "measured". The function is obviously called for each line of the query (about...
1
5068
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...
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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
8629
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...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7170
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...
0
5570
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
4084
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
2611
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
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.