Remove all characters after "hyphen" in field

S

sonofroy

I have field in a query that values are in two parts example

location name 1 - material type
location name 2 - material type
location name 3 - material type

I would like to return in my query everything before the hyphen for example

location name 1
location name 2
location name 3

Thanks
 
F

fredg

I have field in a query that values are in two parts example

location name 1 - material type
location name 2 - material type
location name 3 - material type

I would like to return in my query everything before the hyphen for example

location name 1
location name 2
location name 3

Thanks

NewColumn:Left([FieldName],InStr([FieldName],"-")-2)
 
A

Anthony Fontana

Try this: Left$([textfield],InStr(1,[textfield],"-",1)-1)

Where textfield is the name of the field you want to search. If you know
that the "-" will always occur at location 17 (?) you can replace the entire
instr function with 17.

You might get errors listed if the text field doesn't have a "-"
 
K

Krzysztof Naworyta

Juzer Anthony Fontana <[email protected]> napisaÅ‚

| Try this: Left$([textfield],InStr(1,[textfield],"-",1)-1)
|
| Where textfield is the name of the field you want to search. If you
| know that the "-" will always occur at location 17 (?) you can replace
| the entire instr function with 17.
|
| You might get errors listed if the text field doesn't have a "-"

To avoid this error:

Left([textfield],InStr(1,[textfield] & "-","-",1)-1)

or:

RTrim(Left([textfield],InStr(1,[textfield] & "-","-",1)-1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top