Hi Lorenzo,
In a query, you can use something like this (watch for word wrap):
Stuff = Left$([FieldName], IIf(InStr([FieldName], "--") - 1 > 0,
InStr([FieldName], "--") - 1, 0))
where FieldName is the name of the field. Make the appropriate substitution.
In code, you can use something like this (two variations shown):
Sub TestStuff()
Debug.Print Stuff("Night--P-002")
Debug.Print Stuff("Day--P-002")
'--Does not match search pattern
Debug.Print Stuff("Night-P-002")
Debug.Print
Debug.Print Stuff2("Night--P-002")
Debug.Print Stuff2("Day--P-002")
'--Does not match search pattern
Debug.Print Stuff2("Night-P-002")
End Sub
Function Stuff(strVal As String) As String
Stuff = Left$(strVal, IIf(InStr(strVal, "--") - 1 > 0, _
InStr(strVal, "--") - 1, 0))
End Function
Function Stuff2(strVal As String) As String
Dim intPos As Integer
intPos = InStr(strVal, "--") - 1
Select Case intPos
Case Is > 0
Stuff2 = Left$(strVal, (InStr(strVal, "--") - 1))
Case Else
Stuff2 = "Search string not found."
End Select
End Function
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________