473,388 Members | 1,234 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,388 software developers and data experts.

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

38
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 2284
salzan
38
Any ideas, anyone?
THank you,
Salzan
Feb 23 '08 #2
Scott Price
1,384 Expert 1GB
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
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 Expert 1GB
If you are going to force a calculation, why not write it into the query itself?

Regards,
Scott
Feb 23 '08 #5
salzan
38
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 Expert 1GB
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
Thanks Scott. I'll check out the article and report back on my progress.
Feb 23 '08 #8
NeoPa
32,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
NeoPa
32,556 Expert Mod 16PB
I just looked at Scott's link. It's the D's Bs.
Look in there for pretty well all you could wish to know on the subject.
Feb 28 '08 #11

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

Similar topics

2
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...
1
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...
3
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...
2
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...
4
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. ...
2
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...
1
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. ...
6
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.