Option Compare Database
Private Sub Command954_Click()
Dim strTcodes As String
Dim strYcodes As String
Dim strMcodes As String
Dim strPcodes As String
Dim strScodes As String
Dim TlngLen As Long
Dim YlngLen As Long
Dim MlngLen As Long
Dim PlngLen As Long
Dim SlngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.Tcode & Me.Mcode & Me.Ycode & Me.Pcode) Then
strTcodes = strTcodes & "([Transport code] = """ & Me.Tcode & """) AND "
strYcodes = strYcodes & "([years] = """ & Me.Ycode & """) AND "
strMcodes = strMcodes & "([months] = """ & Me.Mcode & """) AND "
strPcodes = strPcodes & "([POScode] = """ & Me.Pcode & """) AND "
strScodes = strScodes & "([SubPOScode] = """ & Me.Scode & """) AND "
End If
TlngLen = Len(strTcodes) - 5
If TlngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No position number has entered", vbInformation, "ATtruck search form."
Else 'Yep: there is something there, so remove the " AND " at the end.
strTcodes = Left$(strTcodes, TlngLen)
End If
YlngLen = Len(strYcodes) - 5
If YlngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No position number has entered", vbInformation, "ATtruck search form."
Else 'Yep: there is something there, so remove the " AND " at the end.
strYcodes = Left$(strYcodes, YlngLen)
End If
MlngLen = Len(strMcodes) - 5
If MlngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No position number has entered", vbInformation, "ATtruck search form."
Else 'Yep: there is something there, so remove the " AND " at the end.
strMcodes = Left$(strMcodes, MlngLen)
End If
PlngLen = Len(strPcodes) - 5
If PlngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No position number has entered", vbInformation, "ATtruck search form."
Else 'Yep: there is something there, so remove the " AND " at the end.
strPcodes = Left$(strPcodes, PlngLen)
End If
SlngLen = Len(strScodes) - 5
If SlngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No position number has entered", vbInformation, "ATtruck search form."
Else 'Yep: there is something there, so remove the " AND " at the end.
strScodes = Left$(strScodes, SlngLen)
Me.Filter = strTcodes
Me.Filter = strMcodes
Me.Filter = strYcodes
Me.Filter = strPcodes
Me.Filter = strScodes
Me.FilterOn = True
End If
End Sub