Access - query to delete part of a name field in parantheses

Please advise if there is a way to remove part of a field that is enclosed in parantheses or quotes


"Scott, Thomas (Tom)" - becomes "Scott, Thomas"
"Values above average (high)" - becomes "Values above average"

I am able to use Like"*(*" to update or delete the entire record, but not modify just part of the field.

Thank you.
exp vgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
in your Update SQL statement, you can call a user-defined function... like:

in a Module, try add:
Public Function SField(ByVal f As String, ByVal Delimiter As String) As String
       On Error Resume Next
       SField = split(f, Delimiter)(0)
       if Err > 0 Then
           SField = f
      End If 
End Function

Open in new window

then to run your Update SQL statement, try:
update yourTable set fieldname = SField(fieldname, ' (' )

Open in new window

I think you do not need a VBA function for a simple query like this. This straightforward query will do:
Update Table1
SET column1 = Mid(column1,1,InStr(column1,'(')-1) 
WHERE column1LIKE '*(*'

Open in new window

Dale FyeOwner, Developing Solutions LLCCommented:
Both of the previous responses assume that the text wrapped in parenthesis is at the end of your field, but you did not explicitly state that that was the case. So, I would agree with Ryan that a function would be your best approach.

Public Function fnStripParen(Byval SomeValue as Variant) as Variant

    Dim intLeftParen as integer, intRightParen as integer
    Dim strLeft as string, strRight as string

    if isnull(SomeValue) then Exit Function

    'default return value
    fnStripParen = SomeValue

    'No left paren
    intleftParen = instr(SomeValue, "(")
    if intLeftParen = 0 then exit function

    'No right Paren
    intRightParen = instr(intLeftParen, SomeValue, ")")
    if intRightParen = 0 then exit function

    strLeft = IIF(IntLeftParen = 1, "", Left(SomeValue, intLeftParen-1))
    strRight = iif(intRightParen = Len(SomeValue), "", Mid(SomeValue, intRightParen + 1))
    fnStripParen = strLeft & strRight

End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exp vgAuthor Commented:
Thank you everyone
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.