Link to home
Start Free TrialLog in
Avatar of fgwapo botyok
fgwapo botyok

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@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))
Join() hasn't been around for 20 years.  I think it came in with Split().
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().
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
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.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.