Results 1 to 10 of 10
  1. #1
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105

    Post Remove Special Characters using VBA


    In short, on a form I have a field for MAC addresses. I want to remove the : from the MAC address when pasted into the field. Currently I have an excel spread sheet that use to remove the : using a formula. Then I copy and paste it into the field. I want to eliminate this step and have VBA remove the : if it is present in the MAC address pasted in.
    I tried several different code I found but nothing works.

    Thanks in advance.

  2. #2
    madpiet is online now Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    REPLACE()?
    SELECT Replace("My name is Willy Wonka", "i", "a") AS ReplaceString;




    you don't need a custom replacer for this, so no need for VBA at all.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    I tried several different code I found but nothing works.
    Always show what you have used, we are not mind readers.
    As mentioned just use Replace() on the AfterUpdate of the control.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105
    Quote Originally Posted by Welshgasman View Post
    Always show what you have used, we are not mind readers.
    As mentioned just use Replace() on the AfterUpdate of the control.
    Didn't think of including code, this is the last code I tried.

    Private Sub MACAddress_AfterUpdate()
    Dim text As String
    text = ":"
    text = Replace(text, ":", "")




    End Sub




    Thank you.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    What does the text = Replace(text, ":", "") give you, a space where that: was? You want it to remove that space completely? Does Replace(text, ":", null) work?

    I know you can step thru each character and write them out again skipping the : when it is found but easier to use the Replace.

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If that doesn't raise an error, then basically you're replacing : with :
    Try
    Replace([MacAddress],":","")
    Last edited by Micron; 10-02-2024 at 11:39 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    As @Micron mentions, you need to use the control as the item to be searched. You could use text as the string to find, if that is not a reserved word, but I would just use ":" ad be done with it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105
    Does nothing. I am coding this in the "After Update" event in the macaddress field.

  9. #9
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105
    Quote Originally Posted by Micron View Post
    If that doesn't raise an error, then basically you're replacing : with :
    Try
    Replace([MacAddress],":","")

    Thank you. This worked.

    Me.MACAddress = Replace([MACAddress], ":", "")

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What I think the original expression does in English is
    in the string ':' replace ':' with a zls (aka ""). So you convert the variable to an empty string but do nothing to the textbox value.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-02-2018, 03:45 PM
  2. Using Replace() for special characters
    By RayMilhon in forum Programming
    Replies: 2
    Last Post: 01-07-2017, 02:44 PM
  3. Replies: 1
    Last Post: 07-22-2015, 08:11 AM
  4. Need to delete special characters
    By tlrutledge in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:10 AM
  5. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums