Syntax Error 3075

R

Renae

I have set the table field up as at dd/mm/yyyy
(australian) and have set this up also in the visual basic
however I am getting Syntax Error. Here is what I have:
Have I done something wrong?

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

strReport = "Expense Report"
strField = "Expense Date"

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

Thanks

Renae
 
S

Steve Schapel

Renae,

Without trying it out, I am not sure whether your code is objecting to
the data format, but you should always use US format in this
situation, or else use the CLng() function, so I recommend you change
it anyway. But I suspect the syntax error you are getting at the
moment is related to the space in the field name. Try it as...
strField = "[Expense Date]"

- Steve Schapel, Microsoft Access MVP
 

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