Help Passing Parameter From Form to Report

lmoseley7

Board Regular
Joined
Jul 9, 2013
Messages
151
I am quite a novice at Access, although I'm fairly comfortable in Excel so I'm not unfamiliar with VBA and Office Products. We have a report that we run in Access that pulls data based upon a maturity date. One issue we always had was if we ran the report for a date where there was no activity, the date would not appear in the report. I decided to pass the date in from a Form that I built so that the date would appear even if there was no activity for that day. The problem I have now is that when I enter the date in the form the parameter from the report pops up as well. I realize this is because the query under the report uses a parameter on the maturity date field, but if I remove that parameter from the query, the report will display the date in the report, but the results are not filtered by the date.

I'm using the input value in the where clause of the DoCmd statement behind the OK button:
Code:
Private Sub Command2_Click()
    Dim strWhereCondition As String
    strWhereCondition = "[Form_Date_Input] ='" & Me.Form_Date_Input & "'"
    DoCmd.OpenReport "CP MATURING ON THIS DATE", acViewPreview, , strWhereCondition
    DoCmd.Close acForm, "Enter CP Maturity Date"
End Sub

The input box on the form is a text box named Form_Date_Input. In the query I have the following as criteria on the Maturity Date field:
Code:
[[Forms]![Enter CP Maturity Date]![Form_Date_Input]/CODE]

The name of the form is Enter CP Maturity Date.

One other issue, although the date passes to the print preview of the report, when I print the report that field prints a #Name? error.

So I have a few issues.  Hopefully someone can help me with some answers.
 
Open args is just a way to provide some variables to the report. They would work like local variables. That's why you could use them after the first form is closed.

xenou is correct. As to your question
Does the OpenArgs control the data returned by the report, or only allow what is entered to be referenced after the form is closed?
one could also say possibly (for the first part) and yes to the second. In referencing the argument in the report open or load event, you could filter a report or alter its recordsource property. For example, you could filter a report based on the value of a form control containing a Dept value. However, if the user might want to run multiple reports from the form, you wouldn't use this method. You'd hide the form if you don't want it to be seen when the report opens, then unhide it on the report close. This would ensure that a user could not change the Dept value and click to run a new report. If the 1st report is still open, I'm pretty sure it will only display the original data, and not display new data because it was left open. I think the OpenArgs is more useful for controlling subsequent forms though.

Thanks both of you for the insight and knowledge. It is very much appreciated.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top