PDA

View Full Version : Recordest Filter(2)



Maxa
06-11-2008, 07:31 PM
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.

Bob Phillips
06-16-2008, 03:13 AM
Can you post an example database and Excel workbook?

Maxa
06-17-2008, 03:31 AM
9119
Please look in attachments for the spreadsheet.

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

VBA Code:

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




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