How can I code the “if” statements on the attached so that I cna get the results shown in the sample table?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
If statemtns
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » If statemtns
- This topic has 4 replies, 3 voices, and was last updated 14 years, 11 months ago.
Viewing 3 reply threadsAuthorReplies-
WSsgp
AskWoody LoungerMay 20, 2010 at 3:55 am #1224558How can I code the “if” statements on the attached so that I cna get the results shown in the sample table?
I think you’re over-complicating it. Try using the NZ function:-
Role = nz(Role1) & nz(Role2) & nz(Role3) & nz(Role 4) &nz(Role 5)
This will build a string, contatenating the value if there is anything a Role(n) field, or nothing if it’s null.
You can substitute another value instead of null, if you wish, by specifying a value after the field name:-
nz(Role1,”-“)
NZ also works with numeric fields, but defaults to 0 rather than null as the returned value.
-
WSjohnhutchison
AskWoody LoungerMay 20, 2010 at 6:20 pm #1224838Just want to clarify – you want any roles that have data in them returned, with an & between them?
You don’t put put in any spaces? Would you prefer some spaces?
e.g. You have : Biller1&Biller2&Biller3&Biller4&Biller5
Would Biller1 & Biller2 & Biller3 & Biller4 & Biller5 be better? It is more readable.
I think I would use the + operator. + returns nothing if either bit is Null
([role1]+ ” & “) & ([role2]+ ” & “) & ([role3]+ ” & “) & ([role4]+ ” & “) & ([role5]+ ” & “)
But this would have an extra ” & ” on the end, but we don’t know in advance which one is not needed. So we just remove the last three characters using the left function.
left(([role1]+ ” & “) & ([role2]+ ” & “) & ([role3]+ ” & “) & ([role4]+ ” & “) & ([role5]+ ” & “), len(([role1]+ ” & “) & ([role2]+ ” & “) & ([role3]+ ” & “) & ([role4]+ ” & “) & ([role5]+ ” & “))-3)
But if all the roles are empty this would throw an error, so should test that len >3
-
WSbbrown5
AskWoody LoungerMay 20, 2010 at 10:43 pm #1224884With the nz Function I am ending up with:
Role1&&&&
Role1&Role2&&&Because this information will become a part of a User File Import I do need the exact format when there are multiple roles w/o spaces: Role1&Role2
WIth John’s response I get the closest to what I need however don’t need the & at the end when there are multiple roles:
Role1
Role1&Role2&How do I element the final & when there are multiple roles?
-
WSjohnhutchison
AskWoody LoungerMay 21, 2010 at 12:35 am #1224932How do I element the final & when there are multiple roles?
The second part of my solution told you how to get rid of the final &.
Code:left(([role1]+ " & ") & ([role2]+ " & ") & ([role3]+ " & ") & ([role4]+ " & ") & ([role5]+ " & "), len(([role1]+ " & ") & ([role2]+ " & ") & ([role3]+ " & ") & ([role4]+ " & ") & ([role5]+ " & "))-3)
But if you remove the spaces I put in, then change the 3 on the end to 1.
Added later
It is hard to see what is going on in the above because it is so long.
To trim n characters off the end of a piece of text (string), use the left function as follows.
Left(string, Len(string)-n)
If there is a risk that string will be less than n characters long, test for that:
iif(len(string)>n,Left(string, Len(string)-n),string)
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Two blank icons
by
CR2
4 hours, 41 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
7 hours, 6 minutes ago -
End of 10
by
Alex5723
9 hours, 46 minutes ago -
End Of 10 : Move to Linux
by
Alex5723
10 hours, 15 minutes ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
6 hours, 44 minutes ago -
test post
by
gtd12345
15 hours, 47 minutes ago -
Privacy and the Real ID
by
Susan Bradley
5 hours, 54 minutes ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
6 hours, 43 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
20 hours, 8 minutes ago -
Upgrading from Win 10
by
WSjcgc50
7 hours, 33 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
15 hours, 14 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
1 day, 11 hours ago -
The story of Windows Longhorn
by
Cybertooth
23 hours, 32 minutes ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
1 day, 13 hours ago -
Are manuals extinct?
by
Susan Bradley
1 hour, 14 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
1 day, 22 hours ago -
Network Issue
by
Casey H
1 day, 9 hours ago -
Fedora Linux is now an official WSL distro
by
Alex5723
2 days, 10 hours ago -
May 2025 Office non-Security updates
by
PKCano
2 days, 11 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
2 days, 13 hours ago -
pages print on restart (Win 11 23H2)
by
cyraxote
1 day, 14 hours ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
2 days, 15 hours ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
2 days, 15 hours ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
2 days, 22 hours ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
1 day, 15 hours ago -
Asking Again here (New User and Fast change only backups)
by
thymej
3 days, 10 hours ago -
How much I spent on the Mac mini
by
Will Fastie
17 hours, 36 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
1 day, 13 hours ago -
Spring cleanup — 2025
by
Deanna McElveen
3 days, 16 hours ago -
Setting up Windows 11
by
Susan Bradley
2 days, 11 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.