Connecting Tech Pros Worldwide Forums | Help | Site Map

Range dates on Acess report

Newbie
 
Join Date: Aug 2006
Location: michiga
Posts: 13
#1: Aug 22 '06
I am running a report and using date ranges. I will like that when I run the report to see printed those date ranges that I enter on the parameter. Could someone assist me or direct me in the proper direction?
Thank you

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#2: Aug 22 '06

re: Range dates on Acess report


If your date range parameters are being entered via a queries criteria you can't really do this. However, if you are entering your date range parameters on a form you can set up a text field on the report with a source something like this:

=Forms![FormName]![DateFrom] & " to " & Forms![FormName]![DateTo]

Quote:

Originally Posted by josecruz

I am running a report and using date ranges. I will like that when I run the report to see printed those date ranges that I enter on the parameter. Could someone assist me or direct me in the proper direction?
Thank you

Newbie
 
Join Date: Aug 2006
Location: michiga
Posts: 13
#3: Aug 22 '06

re: Range dates on Acess report


Could you tell me how or were do I set the parameters from the report, so the dates can be printed on the report.

Thank you very much
Jose
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#4: Aug 22 '06

re: Range dates on Acess report


Create an empty form and open in design view.

Put two textboxes on the form. Put appropriate label names on the textboxes.

Right click on the first textbox and go down to the bottom of the list to Properties. The first tab is the list of Format Properties and the first item on the list is format. Change this to an appropriate date format. The standard is:

Short Date

Next click on the Data tab and go down to the Default Value property. Type in

Now()

This will set the date to todays date when the form opens.

Then go to the Other tab and change the Name property to

DateFrom

Do the same for the second text box except name it

DateTo

Then add a command button to the report. Use the wizard to indicate that you want to open the relevant report to show all records. (Don't forget to remove the Criteria from the Reports query that you are currently using to set the date range.

When the wizard closes go to the properties of the command button (right click). Go to the event tab and click on the button with the dots beside the On Click event.

The code should look something like this:

Private Sub Command1_Click()
Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acViewPreview

End Sub

You need to change it so it looks like this:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Report Name"
stLinkCriteria = "[DateField] BETWEEN " & Me.DateFrom & " AND " & Me.DateTo
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

End Sub

Close and save the form with an appropriate name. Set it so that this form now opens instead of the report when the user wants to view/print the report.

As before add a textbox to your report as described in previous post.




Quote:

Originally Posted by josecruz

Could you tell me how or were do I set the parameters from the report, so the dates can be printed on the report.

Thank you very much
Jose

Familiar Sight
 
Join Date: Jun 2006
Location: Edmonton, AB
Posts: 179
#5: Aug 23 '06

re: Range dates on Acess report


I'm sorry McCarthy, maybe I misunderstood what JoseCruz was looking for. But you said that you can't do this if using a query.

If you were to open the query in design mode, drag the date field down, and then in the criteria box underneath, type:

Between [Enter Start Date] and [Enter End Date]

This will prompt you for your 2 dates when opening a form that is tied to this query.

Jose, is this what you wanted to do?

comteck
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#6: Aug 23 '06

re: Range dates on Acess report


Hi Comtech

The problem was that JoseCruz wanted to be able to then use the dates inputed by the user to print a date range on the report.

Quote:

Originally Posted by comteck

I'm sorry McCarthy, maybe I misunderstood what JoseCruz was looking for. But you said that you can't do this if using a query.

If you were to open the query in design mode, drag the date field down, and then in the criteria box underneath, type:

Between [Enter Start Date] and [Enter End Date]

This will prompt you for your 2 dates when opening a form that is tied to this query.

Jose, is this what you wanted to do?

comteck

Familiar Sight
 
Join Date: Jun 2006
Location: Edmonton, AB
Posts: 179
#7: Aug 23 '06

re: Range dates on Acess report


That's right... and using the query should work... if I am correct in thinking this is what JoseCruz is looking for.

Anyhow, Jose... you're welcome to try either method you choose, and use the one that works best for your application.

Good Luck.
comteck
Newbie
 
Join Date: Aug 2006
Location: michiga
Posts: 13
#8: Aug 24 '06

re: Range dates on Acess report


mmccarthy and comteck I thank you guys so much for your help. I tried the first method and I believe this is what I need. I am just glad that I have great responces. For a minute I thought I was going to give up. Once again thank you so much.
Jose
Newbie
 
Join Date: Sep 2006
Posts: 1
#9: Sep 5 '06

re: Range dates on Acess report


Gentelman,

In the same quote, I wrote a VB app (not VBA) that requires the user to enter a date range TO and FROM then it connects to and SQL DB and outputs some reports in Access.

How can I pass the dates TO and FROM from the VB app to the access reports?

Thanks for your help.


Quote:

Originally Posted by mmccarthy

Create an empty form and open in design view.

Put two textboxes on the form. Put appropriate label names on the textboxes.

Right click on the first textbox and go down to the bottom of the list to Properties. The first tab is the list of Format Properties and the first item on the list is format. Change this to an appropriate date format. The standard is:

Short Date

Next click on the Data tab and go down to the Default Value property. Type in

Now()

This will set the date to todays date when the form opens.

Then go to the Other tab and change the Name property to

DateFrom

Do the same for the second text box except name it

DateTo

Then add a command button to the report. Use the wizard to indicate that you want to open the relevant report to show all records. (Don't forget to remove the Criteria from the Reports query that you are currently using to set the date range.

When the wizard closes go to the properties of the command button (right click). Go to the event tab and click on the button with the dots beside the On Click event.

The code should look something like this:

Private Sub Command1_Click()
Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acViewPreview

End Sub

You need to change it so it looks like this:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Report Name"
stLinkCriteria = "[DateField] BETWEEN " & Me.DateFrom & " AND " & Me.DateTo
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

End Sub

Close and save the form with an appropriate name. Set it so that this form now opens instead of the report when the user wants to view/print the report.

As before add a textbox to your report as described in previous post.

Reply