G
Guest
I'm building a access search, now the problem is that there are a number of
combo boxs and txt boxs, the txt part I got working but having trouble with
the combo boxes, I did this same query in Query builder, but found I had
troble with it, as the whole lot had to be rewritten when, another search
field was added, when I found this, I though I could use it instead.
I can run the query no problem when the combo are left empty, but as soon as
the combos are used, I get Run-time error '2001'
You canceled the previous operation
when debug is run it is stoped on "Me.FilterOn = True"
this is the code I'm using, "I'm trying to Adapt it from the code found on
Allen Brown's site" currently working with one combo, get it workin then move
onto the others
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.cboFilterCustomer) Then
strWhere = strWhere & "([Customer] = """ & Me.cboFilterCustomer &
""") AND "
End If
If Not IsNull(Me.txtFilterOrderNo) Then
strWhere = strWhere & "([Order Number] Like ""*" &
Me.txtFilterOrderNo & "*"") AND "
End If
'If Not IsNull(Me.cboFilterMaterial) Then
' strWhere = strWhere & "([Material] = """ & Me.cboFilterMaterial &
""") AND "
'End If
If Not IsNull(Me.txtFilterPart) Then
strWhere = strWhere & "([Part Number] Like ""*" & Me.txtFilterPart &
"*"") AND "
End If
'If Not IsNull(Me.cboFilterProducts) Then
' strWhere = strWhere & "([Product] = """ & Me.cboFilterProducts &
""") AND "
'End If
'If Not IsNull(Me.cboFilterBelt) Then
'strWhere = strWhere & "([Belt Width] = """ & Me.cboFilterBelt &
""") AND "
'End If
If Not IsNull(Me.txtFilterTitle) Then
strWhere = strWhere & "([Drawing Title] Like ""*" &
Me.txtFilterTitle & "*"") AND "
End If
If Not IsNull(Me.txtFilterNumber) Then
strWhere = strWhere & "([Drawing Number] Like ""*" &
Me.txtFilterNumber & "*"") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
combo boxs and txt boxs, the txt part I got working but having trouble with
the combo boxes, I did this same query in Query builder, but found I had
troble with it, as the whole lot had to be rewritten when, another search
field was added, when I found this, I though I could use it instead.
I can run the query no problem when the combo are left empty, but as soon as
the combos are used, I get Run-time error '2001'
You canceled the previous operation
when debug is run it is stoped on "Me.FilterOn = True"
this is the code I'm using, "I'm trying to Adapt it from the code found on
Allen Brown's site" currently working with one combo, get it workin then move
onto the others
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.cboFilterCustomer) Then
strWhere = strWhere & "([Customer] = """ & Me.cboFilterCustomer &
""") AND "
End If
If Not IsNull(Me.txtFilterOrderNo) Then
strWhere = strWhere & "([Order Number] Like ""*" &
Me.txtFilterOrderNo & "*"") AND "
End If
'If Not IsNull(Me.cboFilterMaterial) Then
' strWhere = strWhere & "([Material] = """ & Me.cboFilterMaterial &
""") AND "
'End If
If Not IsNull(Me.txtFilterPart) Then
strWhere = strWhere & "([Part Number] Like ""*" & Me.txtFilterPart &
"*"") AND "
End If
'If Not IsNull(Me.cboFilterProducts) Then
' strWhere = strWhere & "([Product] = """ & Me.cboFilterProducts &
""") AND "
'End If
'If Not IsNull(Me.cboFilterBelt) Then
'strWhere = strWhere & "([Belt Width] = """ & Me.cboFilterBelt &
""") AND "
'End If
If Not IsNull(Me.txtFilterTitle) Then
strWhere = strWhere & "([Drawing Title] Like ""*" &
Me.txtFilterTitle & "*"") AND "
End If
If Not IsNull(Me.txtFilterNumber) Then
strWhere = strWhere & "([Drawing Number] Like ""*" &
Me.txtFilterNumber & "*"") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub