Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I separate query data in Expression Builder?

Status
Not open for further replies.

rbnlk

Technical User
Oct 15, 2002
6
0
0
US
Trying to manipulate data in a query field called NAM1 using expression builder. Don't know how to separate the data and reverse it. There is other data mixed in with this field. I only want the data in this field that is separated by a comma and a space. I would be ok to seperate the data into to separate fields.
Here's an example of the data:
PERKINS, JEFFREY D

Here's how I want it:
JEFFREY D PERKINS

Can you help?
 
Hi

The quick explanation of how to do this is to concatenate everything to the left of ", " with everything to the right of ", ". One way to do it is use the InStr function to get the character position of ", " then the left/right functions to get everything to the side.

To get all to left:
Left (YourField, Instr(1, YourField, ", ")-1)

To get all to right:
Right (YourField, Instr(1, YourField, ", ")+ 1)

Put it all together:
Left (YourField, Instr(1, YourField, ", ")-1) & " " & Right (YourField, Instr(1, YourField, ", ")+ 1)

This should be right, but if you're a char or 2 off fool around with the +/- 1's in the InStr function.

As an aside, your data would be easier to manipulate/search if it were divided up over several fields FirstName, LastName, MiddleName, MaidenName, etc. That would allow you to use multiple styles for different formats.

Good luck,
CJ
 
Seems simple enough but I am getting an error of : Invalid procedure call.

Here is the left expression I'm using:
Left([NAM1],InStr(1,[NAM1],", ")-1)

What am I doing wrong?
 
Not sure, it looks OK to me...I'm stumped. There are a few functions (in theory, at least) acting in concert here, so you might be able to pin down the souce if you try slowly building the statement. In other wirds, try InStr(1,[NAM1],", ") and if that works, try InStr(1,[NAM1],", ")-1, then Left([NAM1],InStr(1,[NAM1],", ")-1).

The only thing I can think of is that it may be choking on a record missing the &quot;, &quot; (maybe there's one with just a &quot;,&quot; missing the space or something?). You could add an iif statement to the whole thing like iif instr(1,[NAM1],&quot;, &quot;)<>0,InStr(1,[NAM1],&quot;, &quot;)-1, Left([NAM1],InStr(1,[NAM1],&quot;, &quot;)-1),&quot;Invalid entry&quot;)

Anyone else have an idea?

Good luck,
CJ
 
I am still majorly confused as to why this will not work. I have tried to break it down as you suggest but it still doesn't work. It gives me no data when I run the query and I know it's there. If I use the &quot;like&quot; command it will display the data if I use wildcards i.e. [like &quot;*, *&quot;]
I have also tried it in a similar but different data file.

Still stumped. Don't what to sound ignorant but could it be a properties problem?
 
Now I am truly stumped...sorry! Fooled around a bit with the InStr function and couldn't produce an error. You could try submitting another post with a desperate-sounding title.

Good luck,
CJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top