Results 1 to 11 of 11
  1. #1
    leehi82 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2021
    Posts
    10

    Removing spaces from long number

    Hi Guys,

    Please could someone help me?

    I've created a database for work that stores users information, each user has a unique identifer (UUID) which is a 12 digit number however the place we get our information from displays the 12 digit number like so 1234 5678 9123 as you can see this string contains spaces and my staff like to copy and paste this in to the database but i don't want the spaces included so the forms i have created will only accept 12 digit numbers without the spaces.

    Is there a way i can let my staff copy and paste the string with the spaces and access will automatically remove the spaces?

    Any help would be greatly appreciated!

    Cheers,



    Lee

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    You need to use the Replace() function. Something like:
    Replace("1234 5678 9123"," ","")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    How do you intend to paste? I ask as if the control only accepts 12 chars, then you need to replace before pasting, in some way.

  4. #4
    leehi82 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2021
    Posts
    10
    I could change the contol to accept 14 digits and then do the replace, is there some vba code i could use to automate it?

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Use the replace in the afterupdate event of the control and check you have 12 chars after.?

  6. #6
    leehi82 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2021
    Posts
    10
    Thank you for your replies, and forgive me for being a little dim but could someone help me out with what code i need to type in VBA please?

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    I might use control BeforeUpdate with the expression that Bob suggested. I wouldn't limit the input to x characters as that may change in the future - just remove the spaces.
    EDIT - well that seems to cause some sort of conflict in my testing
    (the macro or function set to the before update or validation rule property...) so if this is a new record perhaps form BeforeInsert or control AfterUpdate as suggested.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Something along the lines of
    Code:
    Me.UUID = Replace(Me.UUID," ", "")
    If Len(Me.UUID) <> 12 Then
        set error message here
        Me.UUID.SetFocus
    End If
    Or perhaps try the Form or control BeforeUpdate event and add Cancel = True after the SetFocus.?
    I believe you would use the .Text property then, and not the .Value property?

    https://docs.microsoft.com/en-us/off...reupdate-event
    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

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    One possible downside to using form update events is that you won't see the effect until you leave the record. If that's on a datasheet or continuous form it might be acceptable to the user. If you navigate to another record on a single record form, you won't see the result until you go back to that record.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    If this is just for the benefit of user input - have you considered using the input mask?

    9999\ 9999\ 9999;;” “

    Users can copy with spaces and value saved as a number (would need to be a double type of that size) or text if you prefer

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    Code:
    Function NoSpaces(pstr As String) As String
    Dim strHold As String
        strHold = RTrim(pstr)
        Do While InStr(strHold, " ") > 0
            strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold, InStr(strHold, " ") + 1)
        Loop
        NoSpaces = Trim(strHold)
    
    
    End Function
    
    
    Private Sub UUID_LostFocus()
        Me.UUID = NoSpaces(Me.UUID)
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Removing all spaces in an email string
    By shuddle in forum Forms
    Replies: 8
    Last Post: 02-04-2021, 10:47 AM
  2. removing multiples of an order number
    By mindbender in forum Access
    Replies: 6
    Last Post: 11-04-2015, 02:07 PM
  3. Removing Unwanted Spaces From Table Fields, Access 2007
    By rd.prasanna in forum Programming
    Replies: 3
    Last Post: 11-11-2013, 05:23 PM
  4. Removing blank spaces created by LEFT statement
    By Paintballlovr in forum Queries
    Replies: 16
    Last Post: 07-09-2013, 12:19 PM
  5. Replies: 1
    Last Post: 04-16-2013, 07:57 PM

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