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

Calling a Report from a Form and passing parameters

38
I have a form in which I collect info from the user and then process various tables. Now, I need to call a report and pass two parameters to it so it’ll only select the desired records for reporting. I’m familiar with the application of OpenArgs and used it successfully to pass several parameters to other forms (using a delimiter to separate and then parse the OpenArgs to pick them). I’m wondering if I can do the same with a report and then I’m not sure how to use these values to select only the records I want.

Any help will be greatly appreciated – even if you can just point me to the right direction to experiment.

Salzan
Feb 22 '08 #1
7 26846
mshmyob
904 Expert 512MB
Yes you can use the OpenArgs to pass to a report

For instance:

Code in Form

Expand|Select|Wrap|Line Numbers
  1. ' vPassedVariable is the value you want to pass to the report
  2. DoCmd.OpenReport "rptSample", acViewNormal, , , , vPassedVariable
  3.  
Code in the Open Event of the Form

Expand|Select|Wrap|Line Numbers
  1. ' vPassedVariable from the form is now in vGotIt
  2. vGotIt = Me.OpenArgs
  3.  
That is how to pass a variable to a report.

To select certain records like you want you might just consider Creating a query and pass the variables to the query and then have the report Record Source set to the query.


I have a form in which I collect info from the user and then process various tables. Now, I need to call a report and pass two parameters to it so it’ll only select the desired records for reporting. I’m familiar with the application of OpenArgs and used it successfully to pass several parameters to other forms (using a delimiter to separate and then parse the OpenArgs to pick them). I’m wondering if I can do the same with a report and then I’m not sure how to use these values to select only the records I want.

Any help will be greatly appreciated – even if you can just point me to the right direction to experiment.

Salzan
Feb 22 '08 #2
salzan
38
Big Thank You. I was thinking the same about passing params to a query. So I have to ask how do I satify the query with the passed argument? I assume that I still call the report and I have to do something when the report opens to satify the query. I don't know what that is. could you help?

As always greatly appreciate your help.
Salzan
Feb 22 '08 #3
mshmyob
904 Expert 512MB
Ok assuming you have a Form called frmTest2 and a Query called qryByClientID and a Report called rptByClient.

In the form you have a Text control called txtClientID. Here you will place a Client ID to get a report on.

In the query you have column called ClientID (from a table) and in the Criteria row you would put [forms]![frmForm2].[txtClientID].

This will filter the query based on the ClientID you put in your form.

Set the Report RecordSource property to qryByClientID.

On the form have a button that calls the form (you do not need to pass a variable to the report because the query is doing all the filtering work and it picked up the variable Client ID from the form).

Hope this is clear.

[
Big Thank You. I was thinking the same about passing params to a query. So I have to ask how do I satify the query with the passed argument? I assume that I still call the report and I have to do something when the report opens to satify the query. I don't know what that is. could you help?

As always greatly appreciate your help.
Salzan
Feb 22 '08 #4
salzan
38
And Thank you again.

Now I'm trying to put it all together and for some reason I'm getting a strange result when executing:

DoCmd.OpenReport "ReportName"

it tries to PRINT it!!! I get a printer prompt - my printer points to a file name so it prompts me for the filename.

I would think this should simply open the report but it doesn't - any ideas?
Salzan
Feb 22 '08 #5
mshmyob
904 Expert 512MB
There are various ways to use the OpenReport method.

The 3 common uses are

Expand|Select|Wrap|Line Numbers
  1. 'send to printer - opens print window depending on some settings before executing
  2. DoCmd.OpenReport "rptName", acViewNormal
  3. ' view report in Print Preview mode
  4. DoCmd.OpenReport "rptName", acViewPreview
  5. ' view report in Report mode.
  6. DoCmd.OpenReport "rptName", acViewReport
  7.  
You decide how you want to do it. Your method will open the Print Window.


And Thank you again.

Now I'm trying to put it all together and for some reason I'm getting a strange result when executing:

DoCmd.OpenReport "ReportName"

it tries to PRINT it!!! I get a printer prompt - my printer points to a file name so it prompts me for the filename.

I would think this should simply open the report but it doesn't - any ideas?
Salzan
Feb 22 '08 #6
salzan
38
THANK YOU ALL. I got it working with acViewPreview. acViewReport is not supported in 2003 version. I also tried a hardcoded value 5 and it gave me an error. but Preview works for me.
Feb 22 '08 #7
mshmyob
904 Expert 512MB
You're welcome....

Cheers,

THANK YOU ALL. I got it working with acViewPreview. acViewReport is not supported in 2003 version. I also tried a hardcoded value 5 and it gave me an error. but Preview works for me.
Feb 23 '08 #8

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

Similar topics

5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
4
by: Greg Iocco | last post by:
Simple problem, but I've checked the newsgroups and couldn't find an answer. On the main swithboard is a command button to open a report. The report I built is based off a query, and the query...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
1
by: Maria | last post by:
Hello! I am new to Crystal reports an I have problems passing parameters form outside to Crystal report an creating a report with data from more than one table This is the problem: I have to...
0
by: lewindha | last post by:
Hi all I am new to ASP.Net and Crystal Reports. We have VS.Net 2003 and Crystal 10 where I work. I have successfully been able to view reports in a web page. My problem now is that I have a...
2
by: Yvon | last post by:
I have a report in a form and it's running fine. I would like to have the same report filter between dates passed form a DateTimePicker to show all records between the two dates. Any help
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
6
by: sarahaman | last post by:
hi all i am new in oracle! i made one simple form with report and i made one print button with trigger.(when-button-pressed) when i press the print button so its giving me whole data,i do not...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.