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


Need help in removing the last string of breadcrumb.


Home > Main Category > Sub1 > Sub2 > Item

Home > Main Category > Sub1 > Item


Home > Main Category > Sub1 > Sub2

Home > Main Category > Sub1

Any help is highly appreciated.

fgwapo botyokAsked:
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.

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

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 FyeOwner, Developing Solutions LLCCommented:

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))
Join() hasn't been around for 20 years.  I think it came in with Split().
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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().
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", "")

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.
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.
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.