Remove last string of a field separated by character ms access VBA

Hello,

Need help in removing the last string of breadcrumb.

Field1:

Home > Main Category > Sub1 > Sub2 > Item

Home > Main Category > Sub1 > Item

Output:

Home > Main Category > Sub1 > Sub2

Home > Main Category > Sub1

Any help is highly appreciated.

fgwapo
fgwapo botyokAsked:
Who is Participating?
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.

GrahamSkanRetiredCommented:
In VBA:
Sub RemoveTail()
Dim strIn As String
Dim strOut As String
Dim strArray() As String

strIn = "Home > Main Category > Sub1 > Sub2 > Item"
strArray = Split(strIn, " > ")
ReDim Preserve strArray(UBound(strArray) - 1)
strOut = Join(strArray, " > ")
End Sub

Open in new window

0

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
Dale FyeCommented:
@Graham,

Learn something new every day.  After 20 years, this is the first time I recall ever seeing the Join( ) function.

@fgwapo botyok

Despite the neat trick with ReDim Preserve, I think this is easier:

NewCrumb = Trim(Left(OldCrumb, instrrev(oldCrumb, ">") - 1))
0
PatHartmanCommented:
Join() hasn't been around for 20 years.  I think it came in with Split().
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GrahamSkanRetiredCommented:
I'm certain that Join() and Split() definitely weren't in VB1 to VB3, but not sure about VB4 (either version - 16 or 32 bit) or VB5. My gut feeling is that it came in with VB6 - possibly at the same time as Replace().
0
Gustav BrockCIOCommented:
Split, Join, Replace, the reverse string functions, Round, and others were introduced with Access 2000.

Actually, you can use these in a one-liner:

    WithTail = "Home > Main Category > Sub1 > Sub2 > Item"

    NoTail = StrReverse(Split(StrReverse(WithTail), " > ", 2)(1))

or, of course, if Item always is the last element:

    NoTail = Replace(WithTail, " > Item", "")

/gustav
0
aikimarkCommented:
Split, Join, and InstrRev functions were added to the VB language with VB6.  Since VBA uses the VB6 compiler/engine, we have that language spec.
0
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.