Sambhaji
Sambhaji

Reputation: 1010

Using NOT LIKE in Filter property of a VBA Recordset

I am using Excel 2003 to connect to a SYBASE database using a VBA recordset. I want to filter the records.

The following is code I have used.

Dim rset As New ADODB.Recordset
rset.Open sQuery, m_db, adOpenForwardOnly
rset.Filter = "Name NOT LIKE 'Dav%'"
rset.Requery

But it is not working and returning all rows. If I use Name LIKE 'Dav%', it's correctly returning records with Name starting with 'Dav'.

What is the problem with Not LIKE? Am I missing something?

Also, I need to use Requery to get the filter work. Is it really required?

Upvotes: 1

Views: 3738

Answers (2)

Ichigo
Ichigo

Reputation: 11

Maybe you can include the NOT LIKE in the sQuery value. Like:

select * from NamesTable where [name] NOT LIKE 'Dav%'

Upvotes: 1

Fionnuala
Fionnuala

Reputation: 91356

The NOT keyword is not allowed in the filter property.

Upvotes: 2

Related Questions