Code not working

G

Guest

Okay I got this off the internet and followed all the directions, it opens my
report but displays all the dates not specific days. Please Help.....


Private Sub Command4_Click()

Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "DailyDispatch"
strField = "TOOnScene"

If IsNull(Me.txtstartdate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " < " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " > " & Format(Me.txtstartdate,
conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtstartdate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If

DoCmd.OpenReport strReport, acViewPreview, , strWhere

End Sub

Private Sub Command5_Click()

DoCmd.Close acForm, Me.Name

End Sub
 
A

Allen Browne

If you open your table in design view, what data type is the TOOnScene
field?

Immediately above the DoCmd.OpenReport line, see:
Debug.Print strWhere
Then when you open the report, open the Immediate Window (press Ctrl+G), and
see what it says is in the filter of the report.
Then type this into the Immediate Window:
? Reports!DailyDispatch.Filter

Hopefully that will help you to track down what is happening.
 
G

Guest

It is Date/Time

Allen Browne said:
If you open your table in design view, what data type is the TOOnScene
field?

Immediately above the DoCmd.OpenReport line, see:
Debug.Print strWhere
Then when you open the report, open the Immediate Window (press Ctrl+G), and
see what it says is in the filter of the report.
Then type this into the Immediate Window:
? Reports!DailyDispatch.Filter

Hopefully that will help you to track down what is happening.
 
G

Guest

Okay found the problem have no idea how to fix though

TOOnScene Between #08/05/1932# And #01/19/2006#

First date is being converted even though I have typed 01/19/06
 
A

Allen Browne

Good. Presumably these are unbound text boxes on your form?
Set their Format property to Short Date, so Access knows how to interpret
them.

More info on handling this type of issue in:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html
 
G

Guest

Also I inserted the calenders and removed the text boxes and this seemed to
clr up the problem.... thanks

Jen
 

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