Use of wildcards in a ServerFilter

G

Guest

I'm trying to use the following code in vbscript on a data access page to
pull only the records whose vendor number ends in 01, and it's not working:

MSODSC.RecordsetDefs("tblVendors").ServerFilter = "VendorNum = " & "*01"

It works fine if I put just one specific vendor number (i.e. 11301) in the
place of *01 and it filters to that 1 record. Please tell me what I'm doing
wrong with the use of wildcards in my code.
 
B

Brendan Reynolds

You need to use LIKE, not =, with wildcards. The following would work if
using an Access form in an MDB ...

"VendorNum LIKE " & "*01"

I'm not familiar with DAPs, though, so I'm not sure whether you use the Jet
'*' wildcard or the ANSI-standard '%' wildcard in DAPs. If you still don't
get the correct result with LIKE and '*', try changing the '*' to '%'.
 
G

Guest

Thanks so much for the quick reply!
This is what ended up working...YOU'RE THE BEST!!!! :)

"VendorNum LIKE " & "'%01'"

--
Thanks again!
Mona-ABE


Brendan Reynolds said:
You need to use LIKE, not =, with wildcards. The following would work if
using an Access form in an MDB ...

"VendorNum LIKE " & "*01"

I'm not familiar with DAPs, though, so I'm not sure whether you use the Jet
'*' wildcard or the ANSI-standard '%' wildcard in DAPs. If you still don't
get the correct result with LIKE and '*', try changing the '*' to '%'.
 
G

Guest

What do I do if I want to use a variable with the wildcard (instead of the 01)?
--
Thanks!
Mona-ABE


Mona-ABE said:
Thanks so much for the quick reply!
This is what ended up working...YOU'RE THE BEST!!!! :)

"VendorNum LIKE " & "'%01'"
 
B

Brendan Reynolds

Well, as I said, I'm not familiar with DAPs, but in a form it would be
something like "VendorNum LIKE %" & VariableNameHere
 
T

Tim Ferguson

What do I do if I want to use a variable with the wildcard (instead of
the 01)?

adSQL = "SELECT .... WHERE VendorNum LIKE " & _
"'%" & uUserSearchString & "%' ORDER BY ..."

Note that ADO always uses single quotes, not double ones, so

"... LIKE ""%" & sUserSearchString & "%"" ..."


will not work.


All the best


Tim F
 
G

Guest

Just wanted to tell you thanks so much for the guidance, Brendan. I tried it
with the variable many different ways and I couldn't get it to work. But
since there are only two possibilities for the variable (1 or 2) I worked
around the problem with an if...then statement. Thanks again for your
help...sometimes DAPs are such a pain!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top