I created a search button for searching a job reference (Called 'CM Code'. The code is below
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append
Dim stFormName As String
Dim stCmCodeFilter As String
If Not IsNull(Me.txtFilterCmCode) Then
strWhere = strWhere & "([CM Code]=" & Me.txtFilterCmCode & ") AND "
End If
stFormName = "MainContractCost"
stCmCodeFilter = "[CM Code]"
DoCmd.OpenForm stFormName, , , stCmCodeFilter
lngLen = Len(strWhere) - 3 'CM Code is 3 numbers
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
However, it does not work. I'm not sure what is missing. Please help!
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append
Dim stFormName As String
Dim stCmCodeFilter As String
If Not IsNull(Me.txtFilterCmCode) Then
strWhere = strWhere & "([CM Code]=" & Me.txtFilterCmCode & ") AND "
End If
stFormName = "MainContractCost"
stCmCodeFilter = "[CM Code]"
DoCmd.OpenForm stFormName, , , stCmCodeFilter
lngLen = Len(strWhere) - 3 'CM Code is 3 numbers
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
However, it does not work. I'm not sure what is missing. Please help!