Results 1 to 10 of 10

Thread: [RESOLVED] Remove 3 leftmost characters

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Location
    Pakistan
    Posts
    289

    Resolved [RESOLVED] Remove 3 leftmost characters

    Hi everyone,
    I need help regarding following situation:
    I have some data in a table which stores supplier name, every supplier name starts with M/S like this:
    M/S ALPHA
    M/S BRAVO
    M/S CHARLIE
    I want to remove "M/S" from the whole field.
    Can anybody help me in this regard.
    Thanks in advance.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Remove 3 leftmost characters

    Use the VB REPLACE function and replace M/S with ""

    Example:
    Code:
    Text1.Text = "M/S ALPHA"
    Text1.Text = Replace(Text1.Text, "M/S","")

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Remove 3 leftmost characters

    In case the left three characters can change, or if they appear elsewhere in the string you can do

    Code:
    Text1.Text = "M/S ALPHA M/S..."
    Text1.Text = Right$(Text1.Text, Len(Text1.Text) - 3)

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Remove 3 leftmost characters

    And because there is more than one way to skin a cat.....
    Code:
    Private Sub Command1_Click()
        Text1.Text = "M/S ALPHA"
        
        'Remove M/S from the string
        Text1.Text = Mid(Text1.Text, 4)
        
        'Trim the leading space that is left
        Text1.Text = Trim(Text1.Text)
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Location
    Pakistan
    Posts
    289

    Re: Remove 3 leftmost characters

    Thanks to all for reply, all mentioned code is working but i want to remove 3 leftmost characters from "Supplier" column of "tbSupplier" table which is of MS Access table having field (column) of "Supplier". I want to remove its 3 character once from whole column through VB 6.0 code. Hope u will understand my problem and reply.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Remove 3 leftmost characters

    Access does support the REPLACE function in SQL queries so you can run an UPDATE query against that table useing REPLACE (as indicated in my first post) and that should clear up your supplier table.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Location
    Pakistan
    Posts
    289

    Re: Remove 3 leftmost characters

    Thanks for reply, your suggestion was very good for me to improve my knowledge, in this scenario, i want to remove characters once a time from the whole column, i want to create a button for this work, when i press button only one time then all data of column "Supplier" will be replaced, can i put your code in a loop? if yes then what will be the procedure. Kindly guide me.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Location
    Pakistan
    Posts
    289

    Re: Remove 3 leftmost characters

    Hi,
    Plz reply my earlier post # 7, i want to remove all data in once, if i press one time command button then all data in column "Supplier" will remove or replace, can you guide me in this regard. As i still in trouble

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Remove 3 leftmost characters

    Use an Update/Edit query. MS Access allows use of Left, Mid & Right functions within the query string. Try writing your query in Access' Query Designer and when you get it working, copy & paste into your VB project remembering to string-format it as needed.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Location
    Pakistan
    Posts
    289

    Re: Remove 3 leftmost characters

    Thanks to all, it is solved my problem, I am very thankful to all of you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width