Ravi Kumar
Registered User.
- Local time
- Tomorrow, 04:25
- Joined
- Aug 22, 2019
- Messages
- 162
hello all ,
The below code was supposed to filter the data in my report using 2 combo boxes in the form .
But Area combo box is working , but when I entered the person name in second one ( even though it is related to same area) it is giving me error as :
ERROR 3464 : Data type mismatch in criteria expression.
Can anyone solve this for me .
Below is the code.
The below code was supposed to filter the data in my report using 2 combo boxes in the form .
But Area combo box is working , but when I entered the person name in second one ( even though it is related to same area) it is giving me error as :
ERROR 3464 : Data type mismatch in criteria expression.
Can anyone solve this for me .
Below is the code.
Code:
Private Sub OK_Click()
On Error GoTo Err_Handler
Dim strReport As String
Dim strDateField As String
Dim StrWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "Person wise data1"
strDateField = "[Week Of Entry ]"
lngView = acViewReport
If IsDate(Me.txtstartdate) Then
StrWhere = "(" & strDateField & " >= " & Format(Me.txtstartdate, strcJetDate) & ")"
End If
If IsDate(Me.txtenddate) Then
If StrWhere <> vbNullString Then
StrWhere = StrWhere & " AND "
End If
StrWhere = StrWhere & "(" & strDateField & " < " & Format(Me.txtenddate + 1, strcJetDate) & ")"
End If
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
If Trim(Me.cbolocationbrief & "") <> "" Then
StrWhere = StrWhere & " And " & _
Application.BuildCriteria("[Area]", vbString, Me.cbolocationbrief.Column(0))
End If
If Trim(Me.cboperson & "") <> "" Then
StrWhere = StrWhere & " And " & _
Application.BuildCriteria("[Person Name]", vbString, Me.cboperson.Column(0))
End If
Debug.Print StrWhere
'DoCmd.OpenReport strReport, lngView, , StrWhere
'DoCmd.OpenReport "OT Details", acViewPreview, , "[Area]='" & Me.cbolocationbrief & "'"
DoCmd.OpenReport "Person wise data1", acViewReport, , StrWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler
End Sub