A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using like in an iif statement



 
 
Thread Tools Display Modes
  #1  
Old April 13th, 2007, 02:28 AM posted to microsoft.public.access.queries
Matt Robson
external usenet poster
 
Posts: 1
Default Using like in an iif statement

I am using a form to supply data to a query it has two different IIF
statements embedded the first returns an empty string if a field is left
blank. the second checks a different box on the form to determine whether the
user wants to search for an exact value or a similiar value.

IIf([Forms]![Purchasing list]![Part
Number]="isnull","",IIf([forms]![purchasing list]![part number1]=Yes, Like
[Forms]![Purchasing list]![Part Number] & "*",[forms]![purchasing list]![PArt
number]))

Access changes it to:

IIf([Forms]![Purchasing list]![Part
Number]="isnull","",IIf([forms]![purchasing list]![part number1]=Yes,([A
List].[PART NO]) Like [Forms]![Purchasing list]![Part Number] &
"*",[forms]![purchasing list]![PArt number]))

-Adding the ([A List].[PART NO])
I have changed the statement and used it to add -99 to the Part Number
instead of using the like operator &"*" and access does not add the extra
text and the statement works as intended. The problem seems to be that when
I use the "like" operator I am doing something wrong.


  #2  
Old April 13th, 2007, 06:09 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Using like in an iif statement

On Thu, 12 Apr 2007 18:28:00 -0700, Matt Robson
wrote:

I am using a form to supply data to a query it has two different IIF
statements embedded the first returns an empty string if a field is left
blank. the second checks a different box on the form to determine whether the
user wants to search for an exact value or a similiar value.


IIf([Forms]![Purchasing list]![Part
Number]="isnull","",IIf([forms]![purchasing list]![part number1]=Yes, Like
[Forms]![Purchasing list]![Part Number] & "*",[forms]![purchasing list]![PArt
number]))


Well, this is not checking to see if the Part Number is null. It is checking
to see if the textbox contains the literal text string "isnull". The second
test will fail as well, since you cannot pass operators such as LIKE out from
an IIF statement - only actual values.

I'd suggest an altogether different criterion:

WHERE [Forms]![Purchasing List]![Part Number] Is Null
OR ([Forms]![Purchasing List]![Part number1] = True AND [Part Number] LIKE
[Forms]![Purchasing List]![PartNumber] & "*")
OR ([Forms]![Purchasing List]![Part number1] = False AND [Part Number]
=[Forms]![Purchasing List]![PartNumber])

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:31 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.