Using the Replace( ) Method in a Field of a form (Access VBA)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JM11
    New Member
    • Jul 2015
    • 14

    #1

    Using the Replace( ) Method in a Field of a form (Access VBA)

    Hello,
    I would like to replace the character 'Â' with an empty space for all the values that belong to the column entitled 'Montant' of a form. Below is the code that I wrote but is not working. Any suggestions? Thank you for your help!

    Code:
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.Maximize
    Dim a As String
    a = MONTANT
    Replace (MONTANT, "Â" , "")
    End Sub
    Last edited by Rabbit; Jul 20 '15, 06:06 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    Replace only Returns a String with the values replaced. You'll then need to stuff the Returned String back into your Control/Field.
    Code:
    MONTANT = Replace (MONTANT, "Â" , "")

    Comment

    • JM11
      New Member
      • Jul 2015
      • 14

      #3
      I tried what you suggested but it is giving me the following error:
      Impossible to attribute a value to that object.

      Please note that not all the values in this column include this character so I just wrote a conditional statement before I did the replace which is:

      If InStr(MONTANT, "Â") <> 0 Then
      MONTANT = Replace(MONTANT , "Â", "")
      End If


      Thank you

      Comment

      • jforbes
        Recognized Expert Top Contributor
        • Aug 2014
        • 1107

        #4
        So, what is MONTANT? Is it a Control on the Form? Is it Field on the Current Record?

        If it is a Field then I would recommend using something like this:
        Code:
        Me!MONTANT.Value = Replace(Me!MONTANT.Value, "Â", "")
        if it is a Control, then:
        Code:
        Me.MONTANT.Value = Replace(Me.MONTANT.Value, "Â", "")

        Comment

        Working...