Re: Runtime Error 2001,when setting filter.



I found out, thanks again.

/Lars

"Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> wrote in message
news:eY525D2aFHA.1404@xxxxxxxxxxxxxxxxxxxxxxx
> WHERE ID IN (23,5,7,99,...)
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Lars Pedersen" <no> wrote in message
> news:ODkGJZ0aFHA.3528@xxxxxxxxxxxxxxxxxxxxxxx
>> The filter may contain a bunch of OR's if the user was not very selective
>> in selecting criteria on the searchform, there could be up to 1500 of
>> them, - together with an longint.
>> I guess this is not a pratical way of doing this, maybe changing the
>> recordsource is better.
>> How do you make use of this IN() ?
>>
>> /Lars
>>
>>
>>
>> "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> wrote in message
>> news:uJUArK0aFHA.3848@xxxxxxxxxxxxxxxxxxxxxxx
>>> How long is this filter?
>>> You should be able to assign any practical filter in code.
>>>
>>> If it's a multi-select list box, use IN () instead of a bunch of ORs.
>>>
>>> If the worst comes to the worst, you could build the complete SQL
>>> statement instead of just the Filter (which is the WHERE clause of an
>>> SQL statement), and assign it to the form's RecordSource.
>>>
>>>
>>> "Lars Pedersen" <no> wrote in message
>>> news:O1ahnvzaFHA.2996@xxxxxxxxxxxxxxxxxxxxxxx
>>>> But I ran into another problem, the filter will to long to be applied
>>>> :-(
>>>>
>>>> /Lars
>>>>
>>>> "Lars Pedersen" <no> wrote in message
>>>> news:%23M1yUgzaFHA.2124@xxxxxxxxxxxxxxxxxxxxxxx
>>>>> Thank you very much, now it works.(I found the code on internet, and
>>>>> was making it work for me. obviously I haven't got the fundamentals
>>>>> right, since I did not se that one)
>>>>>
>>>>> /Lars
>>>>>
>>>>> "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> wrote in message
>>>>> news:uJlxl3yaFHA.3040@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>> The message means that Access cannot complete the current action
>>>>>> (turning the FilterOn), because the previous action is now found to
>>>>>> be invalid. The previous operation is therefore assigning the string
>>>>>> to the Filter, and the message is telling you that the Filter string
>>>>>> you assigned is malformed.
>>>>>>
>>>>>> If ID is a Number field (not a Text field), lose the extra quotes,
>>>>>> i.e.:
>>>>>> Criteria = Criteria & " ID = " & Me![lstShipInfo].ItemData(i)
>>>>>>
>>>>>> That will still be invalid if ItemData(i) is null or a zero-length
>>>>>> string.
>>>>>>
>>>>>>
>>>>>> "Lars Pedersen" <no> wrote in message
>>>>>> news:OGPgk9uaFHA.3144@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>>> Hi there.
>>>>>>> I am getting run-time error 2001 "You cancled the previus
>>>>>>> operation", when my code reach
>>>>>>> the frmFilterOn=true . I can not find out what operation it is
>>>>>>> talking about and why, can anyone help me.
>>>>>>> The code is on a popup search form, ID is autonumber that uniquely
>>>>>>> identifies the record
>>>>>>>
>>>>>>> Code:
>>>>>>> Private Sub cmdUseAsFilter_Click()
>>>>>>> Dim Criteria As String
>>>>>>> Dim i As Variant
>>>>>>> Dim frm As Form
>>>>>>> Set frm = Forms(Me.OpenArgs)
>>>>>>> ' Build criteria string from selected items in list box.
>>>>>>> Criteria = ""
>>>>>>> For Each i In Me![lstShipInfo].ItemsSelected
>>>>>>> If Criteria <> "" Then
>>>>>>> Criteria = Criteria & " OR "
>>>>>>> End If
>>>>>>> Criteria = Criteria & " ID = '" & Me![lstShipInfo].ItemData(i)
>>>>>>> & "'"
>>>>>>> Next i
>>>>>>> ' Filter the form using selected items in the list box.
>>>>>>> frm.Filter = Criteria
>>>>>>> frm.FilterOn = True
>>>>>>> DoCmd.Close acForm, Me.Name
>>>>>>> End Sub
>
>


.



Relevant Pages

  • Re: Help using form filters
    ... entire SQL statement, and pass it to a newly-opened form in the OpenArgs ... then set it as the Form's RecordSource in the Open Event of the ... I am trying to use vb code to set the filter on a form so that only ...
    (comp.databases.ms-access)
  • Re: Allen Brownes Filter - Modification troubles
    ... Access opens the query builder, so you can build the SQL statement. ... (If the RecordSource was a saved query it opens that. ... Behind the scenes, it saves this as a hidden query anyway, but it does work as a SQL statement. ... 'Build the filter string as shown in the example database. ...
    (microsoft.public.access.queries)
  • Re: Subform modifies main forms recordsource - Crash!
    ... The recordsource for the main form is a query. ... > through the querydefs and modify the sql statement accordingly. ... How are you actually applying the filter? ...
    (microsoft.public.access.formscoding)
  • Re: OpenReport from form Problem
    ... Okay I tried to filter by openreport. ... Private Sub cmdAllCountiesSelectedIssues_Click ... > the report itself. ... > OpenReport action to change the report's RecordSource. ...
    (microsoft.public.access.formscoding)
  • Re: Filter By Form
    ... Paul, I think your abilities have outgrown the usefulness of the ... There are several issues with FBF, such as the one you hightlight. ... recordsource) or change type. ... with command buttons for Filter and RemoveFilter. ...
    (microsoft.public.access.modulesdaovba)