Problem with applying filter in a form

G

Guest

Hi,
I got a form and trying to test a code by applying filter. This filter is a
value chosen by a user using a combo box. However when I am running the form
with the click of the filter I am getting an error message "You cancelled a
previous operation" I am getting this error.
Code for filter:
Private Sub cmdFilter_Click()
Dim strwhere As String
Dim lngLen As Long

If Not IsNull(Me.cboFilterIsPrefix) Then
strwhere = strwhere & "([Prefix] = " & Me.cboFilterIsPrefix & ") 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 'Yep: there is something there, so remove the "
AND " at the end.
strwhere = Left$(strwhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strwhere
Me.FilterOn = True
End If
End Sub
While I am on debug mode I saw that the error is coming at the line
Me.FilterOn = True line.
Any help is appreicated. Thanks.
 
G

Guest

Is Me.cboFilterIsPrefix truly a NUMBER? If it isn't and is text then make
sure to add quotation marks.


strwhere = strwhere & "([Prefix] ='" & Me.cboFilterIsPrefix & "') AND "

--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
____________________________________
Access 2000, 2003, 2007, SQL Server 2000, Crystal Reports 10/XI, VB6
WinXP, Vista
 
G

Guest

Thanks for your help Bob. I appreciate it. It occured to me that prfix is not
a number and as you have pointed out that I need to make changes to the code
accordingly. Thanks again Bob.

boblarson said:
Is Me.cboFilterIsPrefix truly a NUMBER? If it isn't and is text then make
sure to add quotation marks.


strwhere = strwhere & "([Prefix] ='" & Me.cboFilterIsPrefix & "') AND "

--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
____________________________________
Access 2000, 2003, 2007, SQL Server 2000, Crystal Reports 10/XI, VB6
WinXP, Vista


Jack said:
Hi,
I got a form and trying to test a code by applying filter. This filter is a
value chosen by a user using a combo box. However when I am running the form
with the click of the filter I am getting an error message "You cancelled a
previous operation" I am getting this error.
Code for filter:
Private Sub cmdFilter_Click()
Dim strwhere As String
Dim lngLen As Long

If Not IsNull(Me.cboFilterIsPrefix) Then
strwhere = strwhere & "([Prefix] = " & Me.cboFilterIsPrefix & ") 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 'Yep: there is something there, so remove the "
AND " at the end.
strwhere = Left$(strwhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strwhere
Me.FilterOn = True
End If
End Sub
While I am on debug mode I saw that the error is coming at the line
Me.FilterOn = True line.
Any help is appreicated. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top