Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:01:18+00:00 2026-06-11T11:01:18+00:00

I’m relatively experienced with Object oriented programming, but this is my first time ever

  • 0

I’m relatively experienced with Object oriented programming, but this is my first time ever working in Office with VBA and I’m entirely stumped by the syntax. I’ve been doing some searching and messing with it for the past hour or so, but have been trouble actually getting a macro that runs successfully and does what I need.

I’m attempting to loop through every cell in an Access table and apply the Trim function to the contents of that cell and, as a bonus, I’d like to remove all extra spaces in the string (if any). I.e. " Trim this__string " would simply become "Trim this string" (I used the underscore there to represent individual, multiple spaces since StackOverflow didn’t want to show my multiple spaces).

Any code example of doing something like this, or at least something to get me close and then I can tinker with it, would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:01:19+00:00Added an answer on June 11, 2026 at 11:01 am

    You can remove leading and trailing spaces with the Trim() function in a query.

    UPDATE YourTable
    SET text_field = Trim(text_field);
    

    If you will be doing this from within an Access session, you could use Replace() to replace a sequence of two spaces with a single space.

    UPDATE YourTable
    SET text_field = Replace(text_field, '  ', ' ');
    

    However you may need to run that Replace() query more than once to get all the contiguous space characters down to only one.

    You could also do a regular expression-based replacement with a user-defined function. I don’t know if that’s worth the effort, though. And a user-defined function is also only available from within an Access application session.

    I overlooked the “every cell in a table” aspect. That makes this more challenging and I don’t think you can solve it with a standard macro or query. You can however use VBA code to examine the TableDef, and iterate through its fields … then call your Trim and/or Replace operations on any of those fields whose data type is text or memo.

    Here’s a rough code outline to identify which fields of a given table are text type.

    Public Sub FindTextFields(ByVal WhichTable As String)
        Dim db As DAO.Database
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
        Set db = CurrentDb
        Set tdf = db.TableDefs(WhichTable)
        For Each fld In tdf.Fields
            If fld.Type = dbText Or fld.Type = dbMemo Then
                Debug.Print "Do something with " & fld.Name
            End If
        Next
        Set fld = Nothing
        Set tdf = Nothing
        Set db = Nothing
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.