Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    33

    Unanswered: Replace specific character in Visual Basic

    guys, please someone help in my code.The question is as following:
    In a form, I have a text box named: txtName which contains customer name.
    If the customer name is for example: Cindy's.
    Then the txtName = "Cindy's"
    Now, in my code, I need to check this txtName field. if contains the single prime ('), I need to replace it as two single primes('')

    My code is:
    Dim Oldtxt as String
    Dim Newtxt as String
    Dim ocn as new connect
    ....
    Oldtxt = txtName.text
    Newtxt = Oldtxt.Replace(" ' ", " '' ")

    str = "Insert into tblName Values('" & Newtxt & "')"

    ocn.execute.str

    I don't know can I achieve my goal by this code since when I debug, it returned that the .Replace method is not found. Then I tried InStr(), still not found.

    It drives me crazy.....

    Please someone give me a hint.

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Try changing this line:

    Code:
    Newtxt = Oldtxt.Replace(" ' ", " '' ")
    to this:

    Code:
    Newtxt = Replace(txtName.text, "'", "''")
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Feb 2004
    Posts
    33

    Thank You So Much

    Oh!! My God!!! You Are Saving My Life. It Works!!!!

    Thank You Thank You!!!

  4. #4
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Thumbs up instr works fine for me

    Dim x, Newx As String
    Dim i As Integer


    x = Me.Text1.Text ' Me.Text1.Text=cindy's
    i = InStr(1, x, "'")
    If i > 0 Then Newx = Left(x, i - 1) & "''" & Mid(x, i + 1)

    ' Newx =now is cindy''s

Posting Permissions

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