Replace statement for VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aisya
    New Member
    • Jun 2009
    • 4

    Replace statement for VB6

    I have use the code below ..

    Code:
    txtName.Text = Trim(Replace(CurrRs("NAME"), "''", "'"))
    ..to actually change back the double quotes stored on the database to single quote when the data calls to the screen.

    as from the screen (user keyed in) to the database I used the code below; to prevent the quotation mark error from pop up.

    Code:
    CurrRs("NAME") = Trim(Replace(txtName.Text, "'", "''"))
    The code works just fine if i key in a string without any quotation mark, it'll will be stored just fine in the database but somehow problem rise when i try to key in a string with quotation mark where the new data doesn't go into the database. There's no error but it's just the data isn't going into the database.

    What should i do to correct these problem?
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Sorry to see you haven't received a response to this question.

    If you have managed to answer it yourself, please let us know what you came up with, as it will help next time someone has a similar question.

    If not, I have some general debugging suggestions. To begin with, try displaying the results of the expression, rather than moving it into the database field. It helps if you can isolate the problem, to simplify investigation.

    In other words, we're trying to pin down whether the problem is actually the text that's coming out of the nested expressions (Trim etc) or what's going into the database.

    This is where the debugging tools built into VB are very helpful. Rather than changing the code to print things out, you can simply set a breakpoint on that line, highlight the Trim(Replace(tx tName.Text, "'", "''")) and see what it returns.

    To be honest, I'm a bit suspicious of the Replace function here. It seems as though it could end up trying to create an infinitely-long string. Think about it - after replacing the first single quote, what is it going to find in the next position in the string? :-)

    Comment

    Working...