View Full Version : Display the Inputbox Results on report


scotthutchings
09-15-2010, 06:39 AM
I have a report that prompts the user to input starting and ending date parameters via an input box. How can I display these values on the report (showing on the report the beginning and ending dates entered)?

Here is my code:
Dim DateFilter As String
Dim Starting As Date
Dim Ending As Date
Select Case Me.optCompetitorDetailLevel
Case 1 ' Detail
stDocName = "Bid - Market Share Competitor Detail"
Case 2 ' Summary
stDocName = "Bid - Market Share Competitor Summary"
End Select
Starting = InputBox("Enter the beginning date", "Beginning Date", "1/1")
Ending = InputBox("Enter the ending date", "Ending Date", Date)
Select Case Me.optCompetitorDateType ' specify if report is to be filtered by proposal date or status date
Case 1 ' Proposal Date
DateFilter = "[ProposalDate] Between #" & Starting & "# AND #" & Ending & "#"
Case 2 ' Status Date
DateFilter = "[DateStatusUpdate] Between #" & Starting & "# AND #" & Ending & "#"
End Select
DoCmd.OpenReport stDocName, acViewPreview, DateFilter, , acIcon

Thanks for your help!
Scott

Trevor G
09-15-2010, 07:14 AM
Add 2 textbox to the report and as you open the report set the value of each inputbox to the textbox

Domcd.OpenReport etc
txtStart.value=Starting.value
txtEnd.Value=Ending.value

If this fails then think of having 2 textbox on the form and place the values of the inputbox to them, then use the control source of the textbox (as mentioned) on the report to use there source, you can always keep the textbox on the form invisible.

scotthutchings
09-15-2010, 07:37 AM
Still no-go. If, following the docmd.openreport command, I enter the code
dtBeginningDate.value = Starting.value
dtEndingDate.value = Ending.value
I get a Compile Error: Invalid Qualifier at Starting.value

If is use the code:
dtBeginningDate.value = Starting
dtEndingDate.value = Ending

or
report.dtBeginningDate.value = Starting.value
report.dtEndingDate.value = Ending.value

then I get error 424 Object Required at 'cmdBillingDate'

Any ideas? Keep in mind that my report name is contained in the variable stDocName (so I don't know how to write reports!stDocName!dtBeginningDate.value because it is looking for the report "stDocName" and not "Bid - Competitor...").

Trevor G
09-15-2010, 08:21 AM
Then go down the line of adding textbox to your form that will have its value from the input boxes, you can then use the source from the report side, it is a work around.

add the following textbox to your form

txtStartDate
txtEndDate

Don't forget to format them to Date/Time

in your code then add the following:

me.txtStartDate.value=starting
me.txtEndDate.value=Ending

scotthutchings
09-15-2010, 10:11 AM
While this would put a Band-Aid on the problem, since I call the report from several different locations (depending on the access rights of the users), I would like to figure out how to pass the values of [Starting] and [Ending] to the report using VBA. I also have this scenario in many different reports using a plethera of different values.

Any other ideas?

pbaldy
09-15-2010, 12:27 PM
That's actually a somewhat unconventional way to gather user input. It would have to be repeated everywhere you want to call the report from. I often use a single form to gather user input for multiple reports that can be called from different places. I use OpenArgs to tell the form what report it's supposed to open. That way any necessary code is only in one place.

To stay with that method your alternatives would include making the 2 variables public (declared in a standard module) and have a public function to return the value of each. Then in your report you'd have:

=FunctionName()

You could also add the values to OpenArgs and use the report open event to put them where they belong (only available in 2002 and after IIRC). Similar to this:

http://www.baldyweb.com/OpenArgs.htm