By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

Calling a Report from a Form and passing parameters

P: 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
Share this Question
Share on Google+
7 Replies


mshmyob
Expert 100+
P: 904
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

P: 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
Expert 100+
P: 904
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

P: 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
Expert 100+
P: 904
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

P: 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
Expert 100+
P: 904
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

Post your reply

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