Solved

Access 2007 VBA - Display conditional values passed into a report on the report

Posted on 2011-02-11
2
253 Views
Last Modified: 2012-05-11
I've got a report that I'm generating dynamically from code like this...

DoCmd.OpenReport "rptExpenditureReport", acViewReport, , "[ProjectID]=" & CStr(lstbxProject.Value) & " AND [Date] BETWEEN #" & CStr(txtStartDate) & "# AND #" & CStr(txtEndDate) & "#"

So I'm passing in a date range to the report.  I need to be able to show that date range in the header of the report.  I can't use the min and max values of the data items returned because that might not be an accurate representation of the data if no data items fall on the dates used in the date range.

What are my options?

thanks
0
Comment
Question by:JosephEricDavis
2 Comments
 
LVL 10

Accepted Solution

by:
VTKegan earned 500 total points
ID: 34873601
You can use the OpenArgs portion of the DoCmd.OpenReport Method.

Then in the OnLoad event of the report, you can set your header to those values.

DoCmd.OpenReport "rptExpenditureReport", acViewReport, , "[ProjectID]=" & CStr(lstbxProject.Value) & " AND [Date] BETWEEN #" & CStr(txtStartDate) & "# AND #" & CStr(txtEndDate) & "#",,CStr(txtStartDate) & ";" & CStr(txtEndDate)

Private Sub Report_Load()
Dim DateArray() as string

If IsNull(Me.OpenArgs) Then
Exit Sub
Else
DateArray = Split(Me.OpenArgs,";")
Me.txtHeaderStartDate = Date(0)
Me.txtHeaderEndDate = Date(1)
End If
End Sub
0
 
LVL 21
ID: 34873775
Since it appear you are collection the data on a form then you can use a form reference this:

For a  a text box on a report set the control source to be:

= "Between " & Format(forms!MyForm.txtStartDate,"mm/dd/yyyy") & " and " &  Format(forms!MyForm.txtEndDate,"mm/dd/yyyy")

Where MyForm is the name of your form

Also:

You do not need to use CStr() for the txtStartDate.

You can use:

DoCmd.OpenReport "rptExpenditureReport", acViewReport, , "[ProjectID]=" & Val(Me.lstbxProject.Value) & " AND [Date] BETWEEN #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#"


Also Date is a reserved word and should  be avoided as field name or object names.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now