query formula (1 Viewer)

CraigDouglas

Registered User.
Local time
Today, 13:59
Joined
Sep 14, 2016
Messages
31
Not sure where to ask my question? I am working on my database and have a formula that puts the company name in if there is no information in the FirstName & Surname field. My problem is that I also want it to take into account the middle name field. I messed around with the formula and tried to get it to put the company name if there is no FirstName, MiddleName & Surname. Here is the formula I have:
FullName: IIf(IsNull([CustomerSurname]),IIf(IsNull([CustomerFirstName]),[CustomerCompanyName],[CustomerFirstName]),IIf(IsNull([CustomerFirstName]),[CustomerSurname],[CustomerFirstName] & " " & [CustomerSurname]))
 

plog

Banishment Pending
Local time
Today, 07:59
Joined
May 11, 2011
Messages
11,648
I also want it to take into account the middle name field

Kinda vague. How do you want to take it into account? Perhaps it would be best to demonstrate your issue with data. Please provide examples of every case and what you hope to end up with each one.
 

CraigDouglas

Registered User.
Local time
Today, 13:59
Joined
Sep 14, 2016
Messages
31
Thank you for the reply. I want the formula to put in the name of the Customers company if there is no information in the FirstName field, the MiddleName field & the Surname field. At the moment the formula works if there is no information in the FirstName field & the Surname field. If there is information in the three name fields I want it to produce a full name ie. FirstName &" "&MiddleName &" "&Surname. Hope this clears it up a bit. Not sure how to represent the data information you ask for?
 

plog

Banishment Pending
Local time
Today, 07:59
Joined
May 11, 2011
Messages
11,648
Not sure how to represent the data information you ask for?

I have this:
ID, FirstName, MiddleName, LastName, CompanyName
1, Steve, R, Smith, Nike
2, , , , Microsoft
3, David, , , Lexus

I want this:
1, Steve R. Smith
2, Nike
3, Lexus
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:59
Joined
Sep 21, 2011
Messages
14,320
Not sure where to ask my question? I am working on my database and have a formula that puts the company name in if there is no information in the FirstName & Surname field. My problem is that I also want it to take into account the middle name field. I messed around with the formula and tried to get it to put the company name if there is no FirstName, MiddleName & Surname. Here is the formula I have:
FullName: IIf(IsNull([CustomerSurname]),IIf(IsNull([CustomerFirstName]),[CustomerCompanyName],[CustomerFirstName]),IIf(IsNull([CustomerFirstName]),[CustomerSurname],[CustomerFirstName] & " " & [CustomerSurname]))

Why not concatenate the three name fields and if len = 0 then populate the company field?
 

Minty

AWF VIP
Local time
Today, 13:59
Joined
Jul 26, 2013
Messages
10,371
To elaborate on Gasman's suggestion;
Code:
IIf(Len([CustomerFirstName] & [CustomerMiddleName] & [CustomerSurname])>0,Trim([CustomerFirstName] & " " & [CustomerMiddleName] & " " & [CustomerSurname]),[CustomerCompanyName])
 

Users who are viewing this thread

Top Bottom