More text manipulation

T

TeeSee

Within a recordset each record has data within brackets e.g. (12345)
How can I delete the contents and the brackets? The string "(12345)"
can be both in the middle or the end of the total field string.

Thanks
 
S

Stuart McCall

TeeSee said:
Within a recordset each record has data within brackets e.g. (12345)
How can I delete the contents and the brackets? The string "(12345)"
can be both in the middle or the end of the total field string.

Thanks

If there are no other values in brackets (and never will be), the following
code should do it:

Dim p1 As Long, p2 As Long
Dim Result As String

'Find the leftmost bracket
p1 = Instr(1, MyField, "(")

'Find the rightmost bracket
p2 = InstrRev(MyField, ")")

'Store all to left of p1 in Result
Result = Left(MyField, p1 - 1)

'Store all to right of p1 in Result
Result = Result & Mid(MyField, p2 + 1)

Debug.Print Result
 

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