How do I delete from dash to the right in string XXXXXX-XXX?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a string of numbers with a dash and 4 letters. I need to get rid of
the dash and letters in an expression. (12345-PPPP) I want the end result
to be 12345

I am using Access 2000

Thank you
 
A couple of approaches...

If the characters to the left of the dash are ALWAYS digits/numeric, you can
use
Value([YourField])

If you want to see the characters to the left of the dash (and they may not
always be a value), you can use something like:
Left([YourField],Instr([YourField],"-")-1)
provided the strings ALWAYS have a dash.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Hi CHW,

This function will chop every thing to the right of the -

' This function will trim all values to the right of -
Public Function MakeGood(strNumber As String) As String
Dim intPosition As Integer
intPosition = -1 + InStr(1, strNumber, "-")
MakeGood = Left(strNumber, intPosition)
End Function

You call this function in code by entering MyVal =
MakeGood(XXXXXX-XXXX).

Good luck
 
Isn't it amazing how may ways there are to get to the same place. Here is a
formula that returns everyting to the left of the dash:
assume x = "12345-PPPP"
replace(x,mid(x,instr(x,"-")),"")
 
Back
Top