Consulting

Results 1 to 3 of 3

Thread: Recordest Filter(2)

  1. #1
    VBAX Newbie
    Joined
    Jun 2008
    Posts
    4
    Location

    Recordest Filter(2)

    Sorry guys,

    prematuraly posted the thread (Solved: Recordset Filter) as solved.

    Thanks to XLD, the code worked well, but another issue arose.

    Actually in the range "a5:a23", I have collection of ids, which I want to extract from the recordset.

    Lets say the recorset itself looks like this:

    123456
    234567
    345678
    ........
    987456

    and the codes in the range look like:
    A B
    1 123456
    2 345678
    3 .......
    4 987456

    by using the code amended by XLD
    rst.Filter = "COUNTERPARTYCODE >= " & "a5" & " and " & "COUNTERPARTYCODE <= " & "a23"

    I get all the records between the "A1" value and "A4" value above. when actually I want to exclude IDs which are not in a range.


    Any help will be very appreciated.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post an example database and Excel workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Jun 2008
    Posts
    4
    Location
    Attachment 9119
    Please look in attachments for the spreadsheet.

    Sheet 1 containes conditions for the search
    Sheet 2 is example of database output

    VBA Code:
    [vba]
    If Worksheets("Sheet2").Range("b3") = "All" Then
    Worksheets("Sheet1").Activate
    rst.Filter = "COUNTERPARTYCODE >= " & "a4" & " and " & "COUNTERPARTYCODE <= " & "a7"
    Else
    rst.Filter="COUNTERPARTYCODE = " & Range("b4")

    End if

    Worksheets("Sheet2").Activate
    Range("a6").CopyFromRecordset rst


    [/vba]

    Range "B3" in Sheet 2 is a key I made, using drop down menu, so I can choose to extract all records specified in conditions (sheet 1) or just single Counterparty Code
    The thing is, when I am passing the range, it gives me all records bigger than 2090503 and smaller than 9605631. When actually I want to skip 5608007 and 950006 (marked yellow in spreadsheet)

    Would be very grateful for any ideas, bros

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •