Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a date parameter

Status
Not open for further replies.

sdb0812

Programmer
May 29, 2003
14
US
Hello,

I am trying to pass two date parameters into a query in order to view a range of information in a report. The code below is what I am currently working with.

If IsDate(txtStartDate.Text) Then StartDate = "'#'" & txtStartDate.Text & "'#'"

If IsDate(txtEndDate.Text) Then EndDate = "'#'" & txtEndDate.Text & "'#'"

FilterString = FilterString & "SearchDateReceived >= " & StartDate
FilterString & " and "
FilterString = FilterString & &quot;SearchDateReceived <= &quot; & EndDate

DoCmd.OpenReport sTarget, acViewPreview, , FilterString

There are no runtime errors. It opens up the report but with no records. Am I passing the date parameters correctly??

thanks,
Scott
 
As far as I know (but I stand corrected), in Access you can retrieve the .Text value only when the control has the focus. But you don't need it.

Then, you don't need to enclose # between quotes (actally you don't need them there).

Then, if you happen to use a different date format from mm/dd/yyyy, you will have to format it:


If IsDate(txtStartDate) Then StartDate = Format(txtStartDate,&quot;dd-mmm-yyyy&quot;)

If IsDate(txtEndDate) Then EndDate = txtEndDate

FilterString = FilterString & &quot;SearchDateReceived >= #&quot; & StartDate
FilterString & &quot;# and &quot;
FilterString = FilterString & &quot;SearchDateReceived <= #&quot; & EndDate & &quot;#&quot;

DoCmd.OpenReport sTarget, acViewPreview, , FilterString



Good luck


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top