Filter on ADO recordset

Set rsColumns = cn.OpenSchema(adSchemaColumns)

How to retrieve recordset that the first two charactors of table's name not including "vw_" at such as "vw_Test"?
leeannAsked:
Who is Participating?
 
TimCotteeConnect With a Mentor Commented:
No, it wouldn't match, 'vwaaa' is always greater than 'vw' and would be excluded no matter what. And 'vx' is always greater than 'vwZZZZZZ.....' no matter how many characters you use, or whatever they are.
0
 
sudhi022299Commented:
if that supports specifying a query then you can do it.
Does it ?

Regards,
Sudhi.
0
 
TimCotteeCommented:
Here is an example of using the filter property of the recordset. You may need to fiddle with it a little though.

Dim cn As New ADODB.Connection
Dim rsColumns As New ADODB.Recordset
cn.ConnectionString = "PROVIDER=MSDASQL;driver={SQL Server};server=osiuk009;uid=;pwd=;database=pilot;"
cn.Open
Set rsColumns = cn.OpenSchema(adSchemaColumns)
rsColumns.Filter = "TABLE_NAME Like 'vw%'"
With rsColumns
    .MoveFirst
    Do
        List1.AddItem rsColumns!TABLE_NAME
        .MoveNext
    Loop Until .EOF
End With
rsColumns.Close
cn.Close
Set rsColumns = Nothing
Set cn = Nothing
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
leeannAuthor Commented:
TimCotte,

As I know, the recordset has only three operators: ">", "<", and "LIKE". There is no "NOT LIKE" operator on the recordset. My problem is to how to get recordset that doesn't include name like "VW_".
0
 
sudhi022299Commented:
I think the recordset filter property supports "NOT LIKE". Check it out.

Is it not possible for you to specify the query to get those records ?

Regards,
Sudhi.
0
 
TimCotteeCommented:
I agree that the recordset filter doesn't seem to support NOT LIKE, however if you want to exclude 'vw%' then the following will do that:

rsColumns.Filter = "TABLE_NAME < 'vw' OR TABLE_NAME >= 'vx'"
0
 
Antonio_PsCommented:
Try this Query to your RecordSet Source:

"Select X From TABLE WHERE X NOT IN (SELECT X FROM TABLE WHERE X LIKE 'vw%')
0
 
leeannAuthor Commented:
Sorry, I tried the following way but failed.
Set rsColumns = cn.OpenSchema(adSchemaColumns)
    rsColumns.Filter = "Select TABLE_NAME WHERE TABLE_NAME NOT IN (SELECT TABLE_NAME WHERE TABLE_NAME LIKE 'vw%')"
0
 
leeannAuthor Commented:
Using OpenSchema(adSchemaColumns) method of the ADO connection will receive all tables the user accessable as well as views. I want a solution to only receive tables not including views which names like "VW_" in the recordset. Do you have any suggestion?
0
 
leeannAuthor Commented:
Using OpenSchema(adSchemaColumns) method of the ADO connection will receive all tables the user accessable as well as views. I want a solution to only receive tables not including views which names like "VW_" in the recordset. Do you have any suggestion?
0
 
sudhi022299Commented:
i think that the query "Select X From TABLE WHERE X NOT IN (SELECT X FROM TABLE WHERE X LIKE 'vw%' " should not be set for the filter propery. It should rather be passed to the open method. Comments please !

Regards,
Sudhi.
0
 
TimCotteeCommented:
sudhi, I agree, you cannot use such complex queries in the filter property. Leeann, have you tried my >= <= selection criteria? It works for me!
0
 
leeannAuthor Commented:
Hi TimCottee,

It's amazing! Your codes work correctly. Would you please tell me how your codes solve my problem? Thank you very much!!!
0
 
TimCotteeCommented:
It works because if you think about what that statement is doing, you see that it is including all tables which are alphabetically < vw i.e. anything starting a,b,c,d... aa,ab,ac..va,vb,vc up to and including vu, or those which are alphabetically after vx inclusive. This is equivalent to the NOT Like operator but can be used in the filter property.
0
 
leeannAuthor Commented:
Thanks, TimCottee. I have increated the point to 100. Please lock this question.

By the way, do you think it is possible that the table name including more than two alphas could equal "vw"?  
0
 
leeannAuthor Commented:
How about others excluding "vw.." such as "mn..."?
0
 
TimCotteeCommented:
leeann, if you mean that you want to have more than one criteria excluded then this will be difficult. There are restrictions on the filter property syntax which mean that the obvious extension of the logic used first time doesn't work. i.e you cannot apparently use (TABLE_NAME < 'vw' OR TABLE_NAME >= 'vx') AND (TABLE_NAME < 'mn' OR TABLE_NAME >= 'mo') because the filter property will not allow an AND operator to join to clauses already joined with an OR operator. I haven't been able yet to work out a statement which works logically given the restrictions placed by the filter property. If you really need to do this, then it would perhaps be better to look at an alternative method.
0
All Courses

From novice to tech pro — start learning today.