Results 1 to 9 of 9
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replacing quote character in string (2003)

    <code>vQ2 = "'"</code> and <code>vQ2 = Chr(39)</code> should both work. What problem do you have with them?

  2. #2
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replacing quote character in string (2003)

    I have included a screenshot: When I continue to Debug, the highlighted line is the Replace Line.
    When hovering over vQ2, it shows the correct value: " ' " (without the spaces)

    <IMG SRC=http://i34.photobucket.com/albums/d130/ForBob/SingleQuoteError.jpg>
    This is triggered on BeforeUpdate when I have added a single quote character at the end of the line for test purposes.
    Trigger is good, InStr() is good, Replace looks good, but RunTime Error comes up anyway.
    There is no validation in the table.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replacing quote character in string (2003)

    BeforeUpdate of the txtDescription control or of the form?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replacing quote character in string (2003)

    You cannot modify the value of a control in its Before Update event. Try putting the code in the After Update event of the control instead.

  5. #5
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replacing quote character in string (2003)

    Before Update of the control.

    Straight text field. Description for a Part Number.
    No combos, no retrictions, only constraint I can think of is that the table calls it as a Required field. Nothing special.

  6. #6
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replacing quote character in string (2003)

    That fixed it. Hans Thanks for pointing out the obvious. Timing is everything.

    A really basic error at this end. Sorry for wasting your time.

    I have been away from Access for a while and have been being pulled in more frequently in the past few months.
    I seem to recall that there is a variable that holds the pending value to be saved, how would I have referenced that?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replacing quote character in string (2003)

    When the Before Update and After Update events occur, the Value property of the control contains the value about to be saved. The OldValue property contains the stored value (the one about to be replaced).

    While the user is typing in the control, the Value and OldValue properties of the control both contain the stored value, and the Text property contains the currently displayed text. This can be used in the On Change event, and also in the On Key Down, On Key Press and On Key Up events. The Text property is only valid if the control has the focus, if you try to refer to the Text property of a control that doesn't have the focus, you'll get an error message.

  8. #8
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replacing quote char in string - SOLVED (2003)

    I need to replace "single quote" characters Chr(39) in a text field. When this works I will duplicate it for "double quote" characters(34) also.
    I have been unable to make this work.
    I am able to locate the character, because the Instr() function is working. But I cannot work out the syntax for the Replace() function.

    I have been using variable vQ2 in Replace() as the search string for single quote { ' }:
    Here are some lines that did not work, no particular order, There are many others that I had tried before commenting them out for history.

    <pre>'vQ2 = "'"
    'vQ2 = "''"
    'vQ2 = Chr(39)
    'vQ2 = Chr(39) + ""
    'vQ2 = Chr(39) + "''" + Chr(39)
    'vQ2 = Chr(34) + Chr(39) + Chr(34)

    If (InStr(txtDescription, Chr(39)) > 1) Then
    MsgBox ("Single Quote Marks are not allowed in descriptions and have been removed")
    txtDescription = Replace(txtDescription, vQ2, "")
    End If</pre>


    This should not be so difficult, I am obviously overlooking the obvious.

    What is the elusive syntax for vQ2 = ' ?

  9. #9
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replacing quote character in string (2003)

    Thanks again for the explanation of the various "value" properties with respect to timing.

    A great reminder.

Posting Permissions

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