Hide all characters after "hyphen"

  • Thread starter Thread starter sonofroy
  • Start date Start date
S

sonofroy

I have a field with records that are in this order

Location1 - Material Name
Location2 - Material Name
Location3 - Material Name

I would like the query to only return the field with everything after the
hyphen to be removed for example

Location1
Location2
Location3

How can I query this without actually trimming the original values out?

Thanks
 
Sonofroy -

Try this (in a query, form, etc.), substituting the right fieldName. The
InStr function will find the first "-" in your field, the Left function will
pull the leftmost characters of the fieldName (the -1 is needed so it doesn't
pull the "-"), and the Trim will remove any extra spaces before and after the
result.

=Trim(Left([fieldName],InStr(1,[fieldName],"-")-1))
 
Back
Top