Writing an IIf Like String statment (1 Viewer)

BrianFawcett

Registered User.
Local time
Today, 01:48
Joined
May 3, 2010
Messages
63
I have to fields in a database, OName and JName. I am trying to write a query to see if I can find matches by comparing the first 6 characters in OName to the JName field.

I know it is something like:

dim Name1 as string
IIf OName(Left,6) Like JName

but I cannot get it right. Can someone help out. Thanks.
 

plog

Banishment Pending
Local time
Today, 03:48
Joined
May 11, 2011
Messages
11,676
The function name is Left and the field you want to use is the first parameter. Also, based on the description of what you want to do, you should use equals sign not LIKE:

IIf Left(OName, 6) = JName
 

BrianFawcett

Registered User.
Local time
Today, 01:48
Joined
May 3, 2010
Messages
63
plog,

What I am trying to do is see if the first 6 characters in ONAME are also in JNAME, so can I say:

IIf Left(OName, 6) LIKE JName
 

MSAccessRookie

AWF VIP
Local time
Today, 04:48
Joined
May 2, 2008
Messages
3,428
plog,

What I am trying to do is see if the first 6 characters in ONAME are also in JNAME, so can I say:

IIf Left(OName, 6) LIKE JName

There is no need to search the string, since Plog's response gives you the first six characters to compare it to.

Use IIf(Left(OName, 6) = JName, {Value if True}, {Value if False}) and you should have exactly what you need.
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:48
Joined
Jan 23, 2006
Messages
15,414
Clear communications is critical when describing a problem.
to fields in a database
I take this to mean 2 fields in a record in a table in a database.
It might be more useful if you described exactly what you are trying to do; even include a couple of examples.

To see if the first 6 characters of these fields are equal
IIf Left(OName, 6)=Left( JName ,6)

But how are you reading all of the records in the table?
Code:
[B]OName   JName[/B]
Bonnie  BonnieSue
JimBob  Jim Bob
Johnston Johnstonville
Chicago     North Chicago
 

plog

Banishment Pending
Local time
Today, 03:48
Joined
May 11, 2011
Messages
11,676
Initially you wanted to compare the first 6 characters in OName to all of JName. Now you want to see if the first 6 characters of OName are anywhere in JName. To do that use this:

IIf(InStr([JName],Left([OName],6))>0)

The above will evaluate true for these values:

OName, JName
James Smith, James Smith
Derrick Jenkins, Derrick Templeton
Bill Davidson, Bill Davis
William Jones, Jeremy Williamson

It will evaluate false for these values:

OName, JName
Shirley Bailey, Sherman Bailey
Michael Hereford, Mike Hereford
Robert Gavin, Bob Gavin
 

Users who are viewing this thread

Top Bottom