error 3464 data type mismatch in criteria expression

N

niuginikiwi

I have a query behind a report which is opened by clicking btnPreview after
supplying 3 criterias from a form.
They are PlantingDetailsID which is a number field, ApplicationID also
number filed and ApplicationDate which is a date field.
When i click btnPrview, the following code executes but then I get the error
3464 which then highlights the Docmd.OpenReport line in the code below. What
am I doing wrong?

Code:

Private Sub btnPreview_Click()
Dim lst As ListBox
Dim cbo As ComboBox
Dim iLen As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
Dim strWhere As String
Dim strDoc1 As String


strDoc1 = "rptOperationSchedule"
Set lst = Me.lstPlantings
If lst.ItemsSelected.Count > 0 Then
strWhere = strWhere & "(PlantingDetailsID" &
MultiSelectSQL(Me.lstPlantings) & ") AND "
End If


Set cbo = Me.cboOperation
If Not IsNull(cbo) Then
strWhere = strWhere & "(OperationID = " & cbo.Column(0) & ")
AND "
End If

If Not IsNull(Me.txtApplicationDate) Then
strWhere = strWhere & "([ApplicationDate] = " &
Format(Me.txtApplicationDate, conDateFormat) & ") AND "
End If

'Did we get anything?
iLen = Len(strWhere) - 5 'Without trailing " AND ".
If iLen < 1 Then
MsgBox "Sorry! one/more criteria must be supplied", vbInformation,
"Criteria Required"
Else
strWhere = Left$(strWhere, iLen)

'Use it for this form.
Me.Filter = strWhere
Me.FilterOn = True


If CurrentProject.AllReports(strDoc1).IsLoaded Then
DoCmd.Close acReport, strDoc1
End If
DoCmd.OpenReport strDoc1, acPreview, , strWhere


End If
Set cbo = Nothing
Set lst = Nothing

End Sub
 

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