Link to home
Start Free TrialLog in
Avatar of thandel
thandel

asked on

How to pass a variable to a report

I have a report that as a variable [BalReason] in it so that when the report is opened it prompts the user for input that is added in to the report.  I would like to now have the input box that the user enters text and then that text is added to the report.

I need this so I can process that input in various ways beside just the report.

Is this possible?

I tried this as a test but it didn't work:

    Dim BalReason As String
    BalReason = "TEST"
    DoCmd.OpenReport "RBillPatientLetter", acViewPreview, , BalReason
 

Thank you.
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Not enough commas..
DoCmd.OpenReport "RBillPatientLetter", acViewPreview,,,, BalReason
<< I would like to now have the input box that the user enters text and then that text is added to the report. >>
  If the form stays open that collected the text, then the simplest is to have the report refer to the control on the form:
=Forms![<myFormName>]![<myControlName>]
That's one way to get data.  Another, which you tried is the OpenArgs argument of the OpenReport command.  To use that however, you need to do something in the report to get what was passed and put it somewhere.  There are various ways to do that.
Another method very similar to that is to use a global variable or array in place of using OpenArgs.  Again, within the report, you need code to fetch the value and do something with it.
HTH,
JimD.
Avatar of thandel
thandel

ASKER

Hi peter57r:,

I tried your solution but the BalReason is not coming in to the report from the code variable.
To retrieve the value in the report, you would use the form open event procedure and do something like:

me.txtboxname = me.Openargs
Avatar of thandel

ASKER

I'm not following, I have code with a variable of text and I am not using a value from a field on a form.  Could you explain how I could pass the variable's data into the report.  Thanks.
All you said in your Q was that you wanted to able to add the text ( that was passed from your form) into your report.

The code using openargs will do that. It adds it to a textbox in your report.

If you want to do more than that you will have to explain.

Avatar of thandel

ASKER

Hmm  I gues there is some confusion.  Currently I have a report that uses a variable that is not defined so it prompts the user for the value.  In this case it is a balance reason.

The report is opened by pressing a button.  Now I would like to use an input box to gather this information and then pass that into the form for use.

Is that explained better?

Thanks.
Avatar of thandel

ASKER

Can I provide any more information to help with a resolution to this?  Thank you.
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thandel

ASKER

I think I've got it, the textbox control source is [OpenArgs].... let me do some testing.

Thanks.
Avatar of thandel

ASKER

Got it working great thanks for the clarification!