Help with access query expressions

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I have a column in one of my Access queries called CustomerName_DBAName. Below is an example of what that data typically looks like.

CustomerName_DBAName
JOHN T. PUBLIC
JAKE A. SMITH JR.
ABC COMPANY
STEVE JONES - DBA: SUPER STORE
BIG COMMUNICATIONS, LLC
SOME BUSINESS INC.
JOE SLOW - DBA: QUICK DELIVERY

I've added two new columns to my query called CustName and Business name. I need to help with expressions to separate the CustomerName part of the CustomerName_DBAName and the DBAName part of the from the DBAName part of CustomerName_DBAName column and put that data in their respective new columns.

I tried this expression "CustName: Left([CustomerName_DBAName],InStr(1,[CustomerName_DBAName],"-")-1)" for the CustName column. It returns the customer name for those entries that contain a hyphen. But, I only get a "#func!" error for those without a hyphen.

Any help would be greatly appreciated.

The end result should look like this:

CustomerName_DBANameCustNameBusinessName
JOHN T. PUBLICJOHN T. PUBLIC
JAKE A. SMITH JR.JAKE A. SMITH JR.
ABC COMPANYABC COMPANY
STEVE JONES - DBA: SUPER STORESTEVE JONESSUPER STORE
BIG COMMUNICATIONS, LLCBIG COMMUNICATIONS, LLC
SOME BUSINESS INC.SOME BUSINESS INC.
JOE SLOW - DBA: QUICK DELIVERYJOE SLOWQUICK DELIVERY

<tbody>
</tbody>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Splitting on the hyphen should not be a problem - we can help you with that.
But before we go down that road, what about entries like "ABC COMPANY"?
I am assuming that should be under BusinessName and not CustName.

So, for entries without hyphens, how do you propose identifying whether the entry is a CustName or a BusinessName?
That logic needs to be clearly defined before we can attempt to program it.
 
Upvote 0
Unfortunately the data I'm working with is pretty sloppy. A business name in front of a hyphen may not have any identifier to work with. Example Inc., Co., or something like that. The one thing that is consistent is the "- DBA: part of the string. Given that I think it would work best that if the "- DBA:" is not present then that entry would go into the CustName column. If the "- DBA:" is present then the part to the left would go in the CustName column and the part to the right would go in the BusinessName column.
 
Upvote 0
OK, try this:

CustName: IIf(InStr([CustomerName_DBAName],"- DBA:")>0,Trim(Left([CustomerName_DBAName],InStr([CustomerName_DBAName],"- DBA:")-1)),[CustomerName_DBAName])

BusinessName: IIf(InStr([CustomerName_DBAName],"- DBA:")>0,Trim(Mid([CustomerName_DBAName],InStr([CustomerName_DBAName],"- DBA:")+6)),"")
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top