Display report with records between two dates

I have a report that has numerous records each displayed on a single line. I would like to ask the user to enter two dates and the report then show records between those dates.

Here are the mechanics of how I would like it to work...
BUTTON (open report)
ASK (start date/end date)
DISPLAY (Report filtered by start and end date)

Any suggestions on which method to use would be appreciated.
timamartinIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
private sub btnOpenReport_click()
dim sDate as date, eDate as date

sdate=nz(Inputbox("Enter Start Date"),Date())
eDate=nz(Inputbox("Enter End Date"),Date())

docmd.openreport "reportName",acviewpreview,,"[DateField] Between #"& sDate & "# and #" & edate & "#"


end sub
Rey Obrero (Capricorn1)Commented:


private sub btnOpenReport_click()
dim sDate as date, eDate as date

sdate=Inputbox("Enter Start Date")
eDate=Inputbox("Enter End Date")

docmd.openreport "reportName",acviewpreview,,"[DateField] Between #"& sDate & "# and #" & edate & "#"


end sub

Open in new window


better if you will use Textboxes for start date and end date



private sub btnOpenReport_click()

if me.txtStartDate & ""="" or Me.txtEndDate & ""="" then
   msgbox "Please Enter Date"
   exit sub
end if

docmd.openreport "reportName",acviewpreview,,"[DateField] Between #"& txtStartDate & "# and #" & txtEnddate & "#"

end sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
timamartinIT ManagerAuthor Commented:
I lose the date picker that way...I don't think people will like that.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Rey Obrero (Capricorn1)Commented:
what date picker are you using?
Dale FyeOwner, Developing Solutions LLCCommented:
I would concur with the 2nd half of Capricorn1's 2nd comment.  Use textbox controls on your form to enter the start and end dates, then in the command button Click event, check to make sure that the dates are valid, or build a criteria string something like:


private sub btnOpenReport_click()

    dim strCriteria as string

    if me.txtStartDate & ""="" AND Me.txtEndDate & ""="" then
        strCriteria = ""
    elseif me.txtStartDate & ""="" AND Me.txtEndDate & ""<>"" then
        strCriteria = "[DateField] <= #" & me.txtEndDate & "#"
    elseif me.txtStartDate & ""<>"" AND Me.txtEndDate & ""="" then
        strCriteria = "[DateField] >= #" & me.txtStartDate & "#"
    else
        strCriteria = "[DateField] BETWEEN #" & me.txtStartDate & "# AND #" & me.txtEndDate & "#"
    endif

    docmd.openreport "reportName",acviewpreview,,strCriteria

end sub

Open in new window

timamartinIT ManagerAuthor Commented:
The way I have been trying to do this is by having a form open with two fields each with a date picker. The user enters two dates and clicks the button then...the report is opened and only records falling between the two dates will populate. The reason I want to use the form is that I want to add other filtering options at a later date. I thought I would be able to pass the two dates as a where condition to filter the report. Is this possible?
Rey Obrero (Capricorn1)Commented:
<I thought I would be able to pass the two dates as a where condition to filter the report. Is this possible?>

YES, the codes was posted above..

did you try it?

1. post the name of your textboxes that you use for entring the dates.

2. post the record source of your report

3. what is the name of the date field?
timamartinIT ManagerAuthor Commented:
I did try your code and it worked fine. Just curious why text boxes are better? I was trying to use a form so I could use the built in date picker when entering the dates.
Rey Obrero (Capricorn1)Commented:
<I was trying to use a form so I could use the built in date picker when entering the dates.>
you can still use the date picker with the text boxes

when you pick a date from the date picker, it will be displayed in the textbox..
Dale FyeOwner, Developing Solutions LLCCommented:
I don't know what version of Access you are using, but with 2007, textboxes have a property (on the Format tab) which allows you to select: Never or  For Dates

If you select the For Dates option, then the date picker will be available.
Rey Obrero (Capricorn1)Commented:
you also need to set the format of the UNBOUND textbox to Short Date
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.