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

IIf



 
 
Thread Tools Display Modes
  #1  
Old February 28th, 2005, 08:37 PM
Stephanie
external usenet poster
 
Posts: n/a
Default IIf

Hello. I have 4 fields: FirstName, NickName, LastName,
OldLastName.

There may not be a NickName and/or an OldLastName.

If there is a NickName, I want to use it rather than the
FirstName. If there is an OldLastName, I want to use it
rather than the LastName.

If Margaret (aka Peggy) Barton marries and changes her
last name to Smith, I want to see Peggy Smith. I was OK
until I added in the OldLastName bit. Thanks, IIf and Nz
confuse me. Here's what I had:

=IIf(IsNull(Forms!Individuals!NickName),Forms!Indi viduals!
FirstName & " " & Forms!Individuals!LastName,Forms!
Individuals!Nickname & " " & Forms!Individuals!LastName)
  #2  
Old February 28th, 2005, 09:46 PM
DebbieG
external usenet poster
 
Posts: n/a
Default

Is this not working?
Are you getting an error? If so, what?
Is this in a form or a report?


"Stephanie" wrote in message
...
| Hello. I have 4 fields: FirstName, NickName, LastName,
| OldLastName.
|
| There may not be a NickName and/or an OldLastName.
|
| If there is a NickName, I want to use it rather than the
| FirstName. If there is an OldLastName, I want to use it
| rather than the LastName.
|
| If Margaret (aka Peggy) Barton marries and changes her
| last name to Smith, I want to see Peggy Smith. I was OK
| until I added in the OldLastName bit. Thanks, IIf and Nz
| confuse me. Here's what I had:
|
| =IIf(IsNull(Forms!Individuals!NickName),Forms!Indi viduals!
| FirstName & " " & Forms!Individuals!LastName,Forms!
| Individuals!Nickname & " " & Forms!Individuals!LastName)

  #3  
Old February 28th, 2005, 09:53 PM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default

"Stephanie" wrote in message

Hello. I have 4 fields: FirstName, NickName, LastName,
OldLastName.

There may not be a NickName and/or an OldLastName.

If there is a NickName, I want to use it rather than the
FirstName. If there is an OldLastName, I want to use it
rather than the LastName.

If Margaret (aka Peggy) Barton marries and changes her
last name to Smith, I want to see Peggy Smith. I was OK
until I added in the OldLastName bit.


It seems to me you just contradicted yourself. If Peggy Barton changed
her name to Smith, wouldn't "Smith" be her LastName, and "Barton" be her
OldLastName? If you really want to use Old:LastName in preference to
LastName, as you said above, then wouldn't you be wanting to see "Peggy
Barton", not "Peggy Smith"?

Thanks, IIf and Nz
confuse me. Here's what I had:

=IIf(IsNull(Forms!Individuals!NickName),Forms!Indi viduals!
FirstName & " " & Forms!Individuals!LastName,Forms!
Individuals!Nickname & " " & Forms!Individuals!LastName)


If you really want to use OldLastName, if available, and fall back to
LastName, you might use this expression:

=Nz([NickName], [FirstName]) & " " & Nz([OldLastName], [LastName])

If you want to use LastName, if available, and fall back to OldLastName,
you might use this expression:

=Nz([NickName], [FirstName]) & " " & Nz([LastName], [OldLastName])

I've left off the Forms!Individuals form qualifiers, thinking that maybe
you don't need them. That would depend on where the expression is being
used, though, so feel free to add them back in if you need to.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


  #4  
Old February 28th, 2005, 10:30 PM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Mon, 28 Feb 2005 12:37:14 -0800, "Stephanie"
wrote:

Hello. I have 4 fields: FirstName, NickName, LastName,
OldLastName.

There may not be a NickName and/or an OldLastName.

If there is a NickName, I want to use it rather than the
FirstName. If there is an OldLastName, I want to use it
rather than the LastName.

If Margaret (aka Peggy) Barton marries and changes her
last name to Smith, I want to see Peggy Smith. I was OK
until I added in the OldLastName bit. Thanks, IIf and Nz
confuse me. Here's what I had:

=IIf(IsNull(Forms!Individuals!NickName),Forms!Ind ividuals!
FirstName & " " & Forms!Individuals!LastName,Forms!
Individuals!Nickname & " " & Forms!Individuals!LastName)


I'd suggest using an expression

NZ([NickName], [FirstName]) & " " & Nz([OldLastName], [LastName])

Since the nick/first and old/new last decisions are independent of one
another, you need two decision points; and the NZ() function is
simpler than the IIF.

John W. Vinson[MVP]
  #5  
Old February 28th, 2005, 10:45 PM
Stephanie
external usenet poster
 
Posts: n/a
Default

My bad.
-----Original Message-----
"Stephanie" wrote

in message

Hello. I have 4 fields: FirstName, NickName, LastName,
OldLastName.

There may not be a NickName and/or an OldLastName.

If there is a NickName, I want to use it rather than

the
FirstName. If there is an OldLastName, I want to use

it
rather than the LastName.

If Margaret (aka Peggy) Barton marries and changes her
last name to Smith, I want to see Peggy Smith. I was

OK
until I added in the OldLastName bit.


It seems to me you just contradicted yourself. If Peggy

Barton changed
her name to Smith, wouldn't "Smith" be her LastName,

and "Barton" be her
OldLastName? If you really want to use Old:LastName in

preference to
LastName, as you said above, then wouldn't you be

wanting to see "Peggy
Barton", not "Peggy Smith"?

Thanks, IIf and Nz
confuse me. Here's what I had:

=IIf(IsNull(Forms!Individuals!NickName),Forms!

Individuals!
FirstName & " " & Forms!Individuals!LastName,Forms!
Individuals!Nickname & " " & Forms!Individuals!

LastName)

If you really want to use OldLastName, if available, and

fall back to
LastName, you might use this expression:

=Nz([NickName], [FirstName]) & " " & Nz

([OldLastName], [LastName])

If you want to use LastName, if available, and fall back

to OldLastName,
you might use this expression:

=Nz([NickName], [FirstName]) & " " & Nz([LastName],

[OldLastName])

I've left off the Forms!Individuals form qualifiers,

thinking that maybe
you don't need them. That would depend on where the

expression is being
used, though, so feel free to add them back in if you

need to.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.

  #6  
Old February 28th, 2005, 10:46 PM
Stephanie
external usenet poster
 
Posts: n/a
Default

It is working, but I wanted to add LastName/OldLastName.
Thanks.

-----Original Message-----
Is this not working?
Are you getting an error? If so, what?
Is this in a form or a report?


"Stephanie" wrote

in message
...
| Hello. I have 4 fields: FirstName, NickName, LastName,
| OldLastName.
|
| There may not be a NickName and/or an OldLastName.
|
| If there is a NickName, I want to use it rather than

the
| FirstName. If there is an OldLastName, I want to use

it
| rather than the LastName.
|
| If Margaret (aka Peggy) Barton marries and changes her
| last name to Smith, I want to see Peggy Smith. I was

OK
| until I added in the OldLastName bit. Thanks, IIf and

Nz
| confuse me. Here's what I had:
|
| =IIf(IsNull(Forms!Individuals!NickName),Forms!

Individuals!
| FirstName & " " & Forms!Individuals!LastName,Forms!
| Individuals!Nickname & " " & Forms!Individuals!

LastName)

.

  #7  
Old February 28th, 2005, 11:14 PM
Stephanie
external usenet poster
 
Posts: n/a
Default

Thanks.
I tried it but it returned: #Error

-----Original Message-----
On Mon, 28 Feb 2005 12:37:14 -0800, "Stephanie"
wrote:

Hello. I have 4 fields: FirstName, NickName, LastName,
OldLastName.

There may not be a NickName and/or an OldLastName.

If there is a NickName, I want to use it rather than

the
FirstName. If there is an OldLastName, I want to use

it
rather than the LastName.

If Margaret (aka Peggy) Barton marries and changes her
last name to Smith, I want to see Peggy Smith. I was

OK
until I added in the OldLastName bit. Thanks, IIf and

Nz
confuse me. Here's what I had:

=IIf(IsNull(Forms!Individuals!NickName),Forms!

Individuals!
FirstName & " " & Forms!Individuals!LastName,Forms!
Individuals!Nickname & " " & Forms!Individuals!LastName)


I'd suggest using an expression

NZ([NickName], [FirstName]) & " " & Nz([OldLastName],

[LastName])

Since the nick/first and old/new last decisions are

independent of one
another, you need two decision points; and the NZ()

function is
simpler than the IIF.

John W. Vinson[MVP]
.

  #8  
Old March 1st, 2005, 02:44 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Mon, 28 Feb 2005 15:14:33 -0800, "Stephanie"
wrote:

Thanks.
I tried it but it returned: #Error


Please post the actual SQL of the query, and the actual field names in
your table.

John W. Vinson[MVP]
  #9  
Old March 1st, 2005, 05:30 PM
Stephanie
external usenet poster
 
Posts: n/a
Default


SELECT Contacts.*
FROM Contacts
WHERE (((Contacts.DonorTypeID)="IN"));

Contacts fields:
ContactID
FirstName
LastName
OldLastName
Nickname
DonorTypeID
....

I have the control source as:
=Nz([Nickname],[FirstName]) & " " & Nz([OldLastName],
[LastName])

Thanks.

-----Original Message-----
On Mon, 28 Feb 2005 15:14:33 -0800, "Stephanie"
wrote:

Thanks.
I tried it but it returned: #Error


Please post the actual SQL of the query, and the actual

field names in
your table.

John W. Vinson[MVP]
.

  #10  
Old March 1st, 2005, 11:52 PM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Tue, 1 Mar 2005 09:30:05 -0800, "Stephanie"
wrote:

I have the control source as:
=Nz([Nickname],[FirstName]) & " " & Nz([OldLastName],
[LastName])


Odd. That looks right to me. Try (for testing)

=Nz([Nickname], [FirstName])

Does this give the nickname if it exists, and the first name if it
doesn't?


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 07:54 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.