RE: Problem with applying filter in a form

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" wrote:

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" wrote:

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.
.



Relevant Pages

  • Re: Filter records in a subform based on list box selection
    ... record source to filter records based on the list box selection. ... I was using code for filtering a form, then changing it for a subform, but I ... Dim strWhere As String ... apply the string as the subform's Filter. ...
    (microsoft.public.access.gettingstarted)
  • Re: Can I use form filtered data for a report?
    ... Private Sub Command38_Click ... DoCmd.OpenReport "Report1", acViewPreview,, strWhere ... You should add a line of code to determine the value of the filter like: ...
    (microsoft.public.access.reports)
  • Re: Search Filter for Report
    ... DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, strWhere, strWhere ... and it now seems to filter the records. ... Private Sub cmdCreateReport_Click ... Allen Browne - Microsoft MVP. ...
    (microsoft.public.access.formscoding)
  • Re: Best way to do this (variable report filtering)
    ... It's picking up the report name in the DoCmd etc, ... Your going to need to apply the strWhere to your report, ... apply the string as the form's Filter. ... Dim strReport As String ...
    (microsoft.public.access.reports)
  • Re: Autofilter with Subtotal Sumif
    ... "Bob Phillips" wrote: ... Which are to filter on any name. ... See a sum of that name's No amounts which in my example ... You could I change the "Sheri" part of Laurent Longre's formula to ...
    (microsoft.public.excel.worksheet.functions)