hi all,
can someone pls tell me what is wrong with this code..
Private Sub cmdSearch_Click()
On Error GoTo errr
Me.InspectionRecords_subform.Form.RecordSource = "SELECT * FROM InspectionRecords " & BuildFilter
Me.InspectionRecords_subform.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
Const ConJetDate = "\#dd\/mm\/yyyy\#"
varWhere = Null
If Me.txtProductCode > "" Then
varWhere = varWhere & "[PRODUCT CODE] like " & Me.txtProductCode & " AND "
End If
If Me.txtDateFrom > "" Then
varWhere = varWhere & "([INSPECTION DATE] >= " & Format(Me.txtDateFrom, ConJetDate) & ") AND "
End If
If Me.txtDateTo > "" Then
varWhere = varWhere & "([INSPECTION DATE] <= " & Format(Me.txtDateTo, ConJetDate) & ") AND "
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = " Where " & varWhere
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
the idea is to search data form certain range of date that i've entered... the result im getting is out of range. is there anything wrong with the code because i'm not the author... actually i'm not so good in this.
pls help me
annie
can someone pls tell me what is wrong with this code..
Private Sub cmdSearch_Click()
On Error GoTo errr
Me.InspectionRecords_subform.Form.RecordSource = "SELECT * FROM InspectionRecords " & BuildFilter
Me.InspectionRecords_subform.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
Const ConJetDate = "\#dd\/mm\/yyyy\#"
varWhere = Null
If Me.txtProductCode > "" Then
varWhere = varWhere & "[PRODUCT CODE] like " & Me.txtProductCode & " AND "
End If
If Me.txtDateFrom > "" Then
varWhere = varWhere & "([INSPECTION DATE] >= " & Format(Me.txtDateFrom, ConJetDate) & ") AND "
End If
If Me.txtDateTo > "" Then
varWhere = varWhere & "([INSPECTION DATE] <= " & Format(Me.txtDateTo, ConJetDate) & ") AND "
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = " Where " & varWhere
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
the idea is to search data form certain range of date that i've entered... the result im getting is out of range. is there anything wrong with the code because i'm not the author... actually i'm not so good in this.
pls help me
annie