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 » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIF Function



 
 
Thread Tools Display Modes
  #1  
Old October 18th, 2009, 08:46 AM posted to microsoft.public.access.gettingstarted
Roger Bell
external usenet poster
 
Posts: 275
Default IIF Function

I have the following in a text box ia Report which is returning an Error:
=Trim("Dear" & " " & IIf([pref]0,[pref],IIf(InStr([firstname],"
")0,Left([Firstname],InStr([Firstname]," ")-1),[firstname])))
What i am attempting is:
If the field [Pref] is greater than 0, then display [Pref], otherwise If the
field [firstname] is greater than 0, display just the first part of this
name, otherwise display the firstname.
The after [pref], works fine, so the problem appears to be in the code
preceeding this.

Any help would be appreciated.
  #2  
Old October 18th, 2009, 12:34 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default IIF Function

Assuming that pref and firstname are text fields, try using Len([pref]) and
Len([firstname]), or, to handle the case where they might be Null,
Len([pref] & "") and Len([firstname] & "")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Roger Bell" wrote in message
news
I have the following in a text box ia Report which is returning an Error:
=Trim("Dear" & " " & IIf([pref]0,[pref],IIf(InStr([firstname],"
")0,Left([Firstname],InStr([Firstname]," ")-1),[firstname])))
What i am attempting is:
If the field [Pref] is greater than 0, then display [Pref], otherwise If
the
field [firstname] is greater than 0, display just the first part of this
name, otherwise display the firstname.
The after [pref], works fine, so the problem appears to be in the code
preceeding this.

Any help would be appreciated.



  #3  
Old October 19th, 2009, 06:31 AM posted to microsoft.public.access.gettingstarted
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default IIF Function

Your test of [pref] is as if it were a number but the rest assumes that is
not correct as you would not say 'Dear 5'.
So if you want to test if it is text larger than zero characters long the
use this --
=Trim("Dear" & " " & IIf(Len([pref])0,[pref],IIf(InStr([firstname],"
")0,Left([Firstname],InStr([Firstname]," ")-1),[firstname])))

But if [pref] is a lookup field then you need to join a table to translate it.

--
Build a little, test a little.


"Roger Bell" wrote:

I have the following in a text box ia Report which is returning an Error:
=Trim("Dear" & " " & IIf([pref]0,[pref],IIf(InStr([firstname],"
")0,Left([Firstname],InStr([Firstname]," ")-1),[firstname])))
What i am attempting is:
If the field [Pref] is greater than 0, then display [Pref], otherwise If the
field [firstname] is greater than 0, display just the first part of this
name, otherwise display the firstname.
The after [pref], works fine, so the problem appears to be in the code
preceeding this.

Any help would be appreciated.

 




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 04:35 AM.


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