Can't get Date Range to work from Form to Report

G

Guest

Hi,
I've followed Allen Browne's directions very closely for creating a form for
a date range to limit results to that date range on a report and can not get
it to work for some reason. I've read many threads on this board which all
say the same thing and it seems to work for everyone else. :(

Here's what I have:
A form with two unbound text boxes called [txtDateBegin] and [txtDateEnd].
The form is called "frmDateRange" and the report is called "Sales Activity
Report". The two unbound text boxes are set to "Short Date" format which the
user inputs a date into each to get the Date Range.

I have a Cancel command button with the following code:

Private Sub Cancel_Click()
DoCmd.Close acForm, Me.Name
End Sub

I have an OK command button with the following on-click code:

Private Sub OK_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "Sales Activity Report"
strField = "SaleDate"

If IsNull(Me.txtDateBegin) Then
If Not IsNull(Me.txtDateEnd) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.txtDateEnd,
conDateFormat)
End If
Else
If IsNull(Me.txtDateEnd) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.txtDateBegin,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtDateBegin,
conDateFormat) _
& " And " & Format(Me.txtDateEnd, conDateFormat)
End If
End If
End Sub

In my query (and placed on my report) there is the field called "SaleDate".

I have also placed text boxes with the controls to display the
[txtDateBegin] and [txtDateEnd] in the report header.

When I click the OK button - nothing happens!

ALSO ****** I have a subreport. How do I pass along the same info to the
subreport?? What am I missing?????? I'm using ver 2003 on XP.

Thanks for your help.
 
G

Guest

OK, I've figured out my problem was that the txt boxes and command buttons
were in the Form Detail section. They should be in the Form Header!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top