Syntax Error 3075

  • Thread starter Thread starter Renae
  • Start date Start date
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
 
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
 
Back
Top