Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Another problem using wildcards in ADO.recordset.filter


Message #1 by "Henning Schloer" <henning.schloer@w...> on Thu, 28 Nov 2002 19:57:20
I am sorry, but I have to post another problem:

I would like to apply a filter containing a statement 
like "code=??????????", but this one dos not seem to work. Manually 
inserted in an Access - query it works fine, but not as an 
ADODB.recordset.filter. Can anybody help?

Thanks a lot in advance!

Henning
Message #2 by "Bob Bedell" <bobbedell15@m...> on Thu, 28 Nov 2002 21:30:47
Hi Henning,

No need to apologize. I was just kidding a bit earlier :) Always good to 
hear from you.

The following lists wildcards supported by Jet SQL that have OLE DB and 
ADO equivalents:

Character    Description                    OLE DB and ADO Equivalent

*            Matches any character or       %
             block of characters in that
             position.

?            Matches any single character   _ (underscore, not hyphen)
             in that position.

#            Matches any single digit       N/A 
             (0-9)              

[list]       Specifies a range of           (list)
             characters

[!list]      Specifies any single character (^list)
             not in list.

Combine these wildcards with the LIKE operator.

So the following code would return a recordset from the Northwind
database containing a single record: 'Davolio'. Call the function with
?WildcardsADO("D").

Function WildcardsADO(chrs As String)
    Dim rst As New ADODB.Recordset
    Dim cnn As ADODB.Connection
    Dim strSQL As String
    
    Set cnn = CurrentProject.Connection
    strSQL = "SELECT LastName FROM Employees " & _
         "WHERE LastName Like '" & chrs & "______'" & ";"

    Debug.Print strSQL
    
    rst.Open strSQL, cnn
    
    Do Until rst.EOF
        Debug.Print rst.Fields(0)
        rst.MoveNext
    Loop
End Function

The Jet version of the WHERE clause would be:

"WHERE LastName Like '" & chrs & "??????'" & ";"

The ADO version uses 6 underscore characters:

"WHERE LastName Like '" & chrs & "______'" & ";"

Now, there are always exceptions to these rules, and the Filter property
of an ADO recordset is one of them. The following example from the code 
you posted earlier works just fine:

rsAnbieterbefragung.Open query_string, CurrentProject.Connection, _ 
   adOpenKeyset, adLockOptimistic 
rsAnbieterbefragung.Filter = "cs_uri_stem Like '*" & strCriteria & "*'" 

So you'll have to experiment a little. But for your present purposes,
an underscore _ is the ADO equivalent of the Jet SQL ?

Best,

Bob



> I am sorry, but I have to post another problem:

> I would like to apply a filter containing a statement 
l> ike "code=??????????", but this one dos not seem to work. Manually 
i> nserted in an Access - query it works fine, but not as an 
A> DODB.recordset.filter. Can anybody help?

> Thanks a lot in advance!

> Henning

  Return to Index