Access - Trim All Fields at Once

Please offer if there is a way to have a default statement that will trim all fields at once. Currently I wrote Trim field by field, and some tables have a lot of fields.

Thank you.
exp vgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
There is no "default statement" that works on all fields, but you could use VBA to do so:

    Dim tdf    As DAO.TableDef
    Dim dbs    As DAO.Database
    Dim fld    As DAO.Field

    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs("Your Table")

    For Each fld In tdf.Fields
        If fld.Type = dbText Then
            dbs.Execute "UPDATE [Your Table] SET [" & fld.Name & "]=Trim([" & fld.Name & "])"
        End If
    Next fld

Open in new window

You'd have to change "Your Table" to match the table you want to trim.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exp vgAuthor Commented:
Thank you Scott. I am not quite at the VBA point of using Access - but when I am - I will try this.
exp vgAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.