hi...
i have a function that check the value entered to the text box with value in a query call CALLRECORD. The field that i need to check in the query is a calculated field call MONTH that the value derived from field INSEPCTION DATE in the table Inspection Records - use in CALLREPORT QUERY. In my form call Search, i would like to enter the value for PRODUCT CODE & MONTH call the function to produce the output in the CALLREPORT_subform.
Well at the moment i have problem with the code seems that it doesn't running well. i don't know what is wrong but i have the idea that the problem maybe come from the field MONTH or my declarations...
can somebody help me...
i really appreciate this
my code:
Private Sub cmdSearch_Click()
On Error GoTo errr
Me.CALLREPORT_subform3.Form.RecordSource = "SELECT * FROM CALLREPORT " & BuildFilter
Me.CALLREPORT_subform3.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
varWhere = Null
If Me.txtProductCode > "" Then
varWhere = varWhere & "[PRODUCT CODE] like " & Me.txtProductCode & " AND "
End If
If Me.txtMonth > "" Then
varWhere = varWhere & "[MONTH] like " & Me.txtMonth & " 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
i have a function that check the value entered to the text box with value in a query call CALLRECORD. The field that i need to check in the query is a calculated field call MONTH that the value derived from field INSEPCTION DATE in the table Inspection Records - use in CALLREPORT QUERY. In my form call Search, i would like to enter the value for PRODUCT CODE & MONTH call the function to produce the output in the CALLREPORT_subform.
Well at the moment i have problem with the code seems that it doesn't running well. i don't know what is wrong but i have the idea that the problem maybe come from the field MONTH or my declarations...
can somebody help me...
my code:
Private Sub cmdSearch_Click()
On Error GoTo errr
Me.CALLREPORT_subform3.Form.RecordSource = "SELECT * FROM CALLREPORT " & BuildFilter
Me.CALLREPORT_subform3.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
varWhere = Null
If Me.txtProductCode > "" Then
varWhere = varWhere & "[PRODUCT CODE] like " & Me.txtProductCode & " AND "
End If
If Me.txtMonth > "" Then
varWhere = varWhere & "[MONTH] like " & Me.txtMonth & " 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