Help with one of allen browne's tips for limiting a report to dates

M

Michael

I have followed his tutorial at http://allenbrowne.com/casu-08.html and made
the from for the dates and did every step correctly (I think) and when I
click the ok button... nothing happens. The cancel button works. Also I was
wondering if I can use two calendars instead of text boxes? Below is the
code I have only altered the

strReport = "Order Details"
strField = "Data Partenza"

Do I have to make changes to my query as well or is all the filtering done
with this code? Sorry if it is a dumb question.
Michael


Private Sub Command4_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 = "\#dd\/mm\/yyyy\#"

strReport = "Order Details"
strField = "Data Partenza"

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

' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
 
A

Allen Browne

Your date format string is wrong.

Regardless of your regional settings, a literal date in a SQL string or VBA
code must be in mm/dd/yyyy format. Change your code back to the original.

For more on this issue, see:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
 
M

Michael

Thanks Allen, I changed it back, but still nothing when I click ok. Do I
need to make any changes to the report or the underlying query?
Michael
 
M

Michael

Sorry Allen, I just saw that some how I lost the event procedure on the ok
button, the code was still there.. but no link to the button. Now I get a
error at " strWhere = strField & " < " & Format(Me.txtEndDate," when I
push the ok button. The error is "compile error:Syntax error" I checked to
make sure the box was in fact "txtEndDate" and the proper name for the field
is "Data Partenza"

Michael
 
A

Allen Browne

That line looks incomplete. The format string and closing bracket are
missing.
 
M

Michael

I am sorry if I did not include the entire line. The highlighted area starts
at the left margin and ends at the comma next to the "(Me.txtEndDate,"

michael

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtEndDate,
conDateFormat)
End If
 
M

Michael

got it... I brought the conDateformat to the same line and now it works..
thank you for you help
michael
 

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

Similar Threads

Combine Code 2
Adding another Text Box for a Report 1
visual basic 1
Running report from input form 6
Syntax Error 3075 1
No data report 2
How do I get a filter to apply to all my subreports? 1
Date error 1

Top