Solved * and % (1 Viewer)

mloucel

Member
Local time
Today, 12:37
Joined
Aug 5, 2020
Messages
181
Hello Gurus.

I spent a pretty bad time trying to figure out why a simple line of code like this:

Code:
Me.Filter = "[ItemCode] like '*" & Me.Search & "*'"

did not produce any results, I spent a couple of hours looking online and I found out that sometimes you have to use "%" instead of "*", and believe my eyes it worked, the whole thing worked..

Code:
Me.Filter = "[ItemCode] like '%" & Me.Search & "%'"

Now question WHY?

It doesn't make any sense, this comes from a routine to do a search on a cont form, a friend sent me.

Any Ideas WHY?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 05:37
Joined
Jan 20, 2009
Messages
12,859
Note that ADODB wildcards are the percent (%) for up to multiple characters and underscore (_ ) for a single character.
 

mloucel

Member
Local time
Today, 12:37
Joined
Aug 5, 2020
Messages
181
The wildcard is % if you have ticked the option 'Use SQL Server compatible syntax ANSI 92' in the Object Designers tab in Access Options.
If so, you should also look at using Alike instead of Like.

Leave the option unticked to use *as your wildcard. See
Sorry for the late reply, I've been a bit busy, I have to check that, as far as I remember, I have never done that [ansi92] as a matter of fact my knowledge doesn't go that far, but who knows maybe I did it without even knowing what I was doing, I'll check today.
 

isladogs

MVP / VIP
Local time
Today, 20:37
Joined
Jan 14, 2017
Messages
18,258
I learned about it many years ago the hard way when I set the ANSI 92 option and forgot all about it for a while.
Then Access started changing instances of Like to ALike and I eventually worked out what I'd done
 

mloucel

Member
Local time
Today, 12:37
Joined
Aug 5, 2020
Messages
181
The wildcard is % if you have ticked the option 'Use SQL Server compatible syntax ANSI 92' in the Object Designers tab in Access Options.
If so, you should also look at using Alike instead of Like.

Leave the option unticked to use *as your wildcard. See
Right on the money... My Friend use SQL server hence he changed the * for a %, I got rid of the ANSI 92 check mark, and changed the % for * and the statement works as programmed, thanks so much for your help.
 

Users who are viewing this thread

Top Bottom