Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001

    Unanswered: String Manipulation using VBA

    I have a TextBox and a command button on a form.
    I have some text in the textbox. I need to update this
    text when i click on the command button.

    For Example:
    if my Textbox had(before): Access is a database.

    if i put my cursor in between "Access" and "is" in the above
    text and click the command button the text needs to be updates as given below.

    my textbox should display(after):Access aaaa is a database.

    It is easy to update a text in the end how do we do it in the middle.

    how is this possible.

    I hope i am clear.

    Thanks in Advance.

  2. #2
    Join Date
    May 2002


    This was a bit more complex than I thought it was going to be, hope it helps.

    The form needs three objects:

    1-textbox named text0 'Default value is "Access is a database"
    2-textbox named text1 'Visible property is false
    3-command button named command 1

    Paste the following code to the On Click event of the command button

    Dim x As Integer
    Dim y As String
    Dim z As String
    Dim a As String
    Dim mylen As Integer
    Dim mylena As Integer
    Dim mylenb As Integer
    Dim mylenc As Integer
    Dim ftext As String
    Dim ecalc As Integer
    Dim etext As String

    Text1.Value = "" 'Sets hidden textbox value to null

    x = InputBox("Enter the starting point (Numeric Value)") 'Numeric Value

    y = InputBox("What text do you wish to append?")

    z = [Text0] 'Text0 is the name of the text box containing "Access is a database"

    a = [Text1] 'Text1 is a hidden text box on the form

    mylen = Len(z)

    mylena = Len(y)

    'Error trapping for end point
    If mylena > mylen Then
    mylena = mylen + 1
    End If
    'Error trapping end

    ftext = Left(z, x) & "" & y
    mylenb = Len(ftext)
    ecalc = (mylenb - mylena) + 1
    etext = Mid(z, ecalc)

    Text1 = ftext & "" & etext
    Text0 = Text1

    End Sub

Posting Permissions

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