{
  "id": "2000-april-trimming-spaces",
  "slug": "2000-april-trimming-spaces",
  "url": "https://dwillis.github.io/uplink/article/2000-april-trimming-spaces.html",
  "year": 2000,
  "month": "April",
  "monthNum": 4,
  "headline": "Trimming spaces",
  "kicker": "QUICK TIP",
  "author_name": "Tom McGinty",
  "author_title": "Training Director",
  "affiliation": "NICAR",
  "summary": "A tutorial on creating and using a Microsoft Access module that removes leading, trailing, and extra spaces between words in database fields.",
  "keywords": [
    "Access",
    "module",
    "spaces"
  ],
  "topics": [
    "Technology",
    "Data & Databases"
  ],
  "technologies": [
    "Access",
    "Visual Basic"
  ],
  "full_text": "This module will trim leading and trailing spaces in a field, as well as extra spaces between words. For example, it will turn \"(space) Tom (space)(space)(space)McGinty(space).\" into \"Tom(space)McGinty\".\n\nTo find the Microsoft article about this module, go to www.microsoft.com/directory and click on \"Searchable Knowledge Database.\" Search for story number Q148396. From there you can copy and paste this module directly into Access.\n\nHere's how the module works: Go to the module tab on your database window and click on the \"new\" button. The window that pops up should have the following two lines at the top: Option Compare Database Option Explicit If it does not, add them. Next, type the following syntax below those two lines:\n\nFunction StripExtraChars (PassedStr, RemoveExtraChar$) On Local Error GoTo stripExtraChars_Em Dim i As Integer, GotChar As Integer Dim HoldStr As String, HoldChar As String , Exit if passed value is Null. If IsNull (PassedStr) Then Exit Function Trim extra characters from passed , string. PassedStr = Trim$(PassedStr) , Cycle through string and remove , extra string characters specified in , the RemoveExtraChar value. For i = 1 To Len(PassedStr) HoldChar = Mid$(PassedStr, i, 1) If HoldChar = RemoveExtraChar\n\nThen If GotChar = False Then GotChar = True HoldStr = HoldStr & HoldChar End If Else GotChar = False End If If Not GotChar Then HoldStr = HoldStr & HoldChar End If Next i StripExtraChars HoldStr StripExtraChars_End: Exit Function StripExtraChars_Err MsgBox Error$ Resume StripExtraChars_End End Function\n\nNext, under the \"Debug\" menu, choose \"Compile and save all modules.\" It will prompt you to name the module. Name it \"TrimSpaces\" and then close the module.\n\nNow, let's say you have a field called NAME that has extra spaces between first and last names, and unwanted spaces at the beginning and end of some of the names First, create a new field in your table called \"NEWNAME\"(NEVER change your original data).\n\nThen start a new query, add your table to the query and then, under the \"Query\" menu, choose \"Update Query.\" Pull the \"NEWNAME\" field down into the \"Field\" row of the update query. Then type this in the \"Update To:\" row of the query:\n\nStripExtraChars([NAME],Chr$(32))\n\nThat applies the new module you just created to the NAME field and puts the results into the NEWNAME field. The second argument of the function, Chr$(32)), is the ASCII code for spaces. The SQL for the same update query would look like this: update TABLENAME set NEWNAME = StripExtraChars([NAME],Chr$(32)) Tom McGinty can be reached by e-mail at tmcginty@nicar.org",
  "provenance": {
    "extracted_by": "anthropic/claude-sonnet-4-6",
    "extracted_at": "2026-07-05",
    "verified": true
  },
  "similar": [
    {
      "slug": "2002-february-updating-with-access",
      "score": 0.454
    },
    {
      "slug": "1994-november-sociology-101",
      "score": 0.15
    },
    {
      "slug": "2004-november-extra-extra",
      "score": 0.145
    },
    {
      "slug": "2003-marchapril-extra-extra",
      "score": 0.14
    },
    {
      "slug": "2000-june-fronts-for-forms",
      "score": 0.12
    }
  ],
  "html_url": "https://dwillis.github.io/uplink/article/2000-april-trimming-spaces.html",
  "json_url": "https://dwillis.github.io/uplink/article/2000-april-trimming-spaces.json"
}