Full Version: Extract part of a field
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
CrazyJo
One field - Address. It contains the street address and the PO Box address. I want to extract the data starting with "PO Box" and the information to the right of it. Any suggestions?
stevecreedon
Hi,

Can you give us an example of the data in the field 'Address'?
CrazyJo
32 E Market St PO Box 72

I want only the information starting with PO Box and what ever follows.
fkegley
You can use InStr to find the phrase PO Box:

In a query,

P: InStr(1, [FieldName], "PO Box")

P1: Mid$([FieldName], P)

P will be the position where PO Box starts
P1 then will be the portion of the original field that begins with PO Box
CrazyJo
OK- you are to advanced for me - when I put this in the query I receive an error.
Instr(1,[Address],"PO Box")Mid$([Address],P)
fkegley
Each belongs in its own Field: cell in the query.
CrazyJo
That fixed the problem. Thank You!
domenick2x
Won't that run into issues if there's a P in the address, as in:

1234 Davis Place PO Box 1234

??
fkegley
You're welcome. I am glad I could help.
fkegley
No, I am finding PO Box---the entire phrase, not just the P.
domenick2x
QUOTE
No, I am finding PO Box---the entire phrase, not just the P.


Right, sorry. I hit super-dyslexia on that one. sad.gif
fkegley
No problem, thanks for checking me---I do make mistakes from time to time, more often than I will admit in public.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.