Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trim the fields name

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi,

When I import excel spreadsheet into Access, the fields names have blanks at the end
(e.g. [Invoice Number ])

How can I get rid of those blanks (using VBA)

Thanks.
 
use the trim() function.

dim FieldName as string
FieldName = trim(InputFieldName)
 
I realize now that the answer I gave you was inappropriate.

To change the field names, you need to work with table defs.
Just off the top of my head (may have some compilation or logic errors, but it should get you started)

Dim MyDb as database
set mydb = currentdb

dim MyTDF as tabledef
set mytdf = mydb.tabledefs("TheTableWithExcelFields")

dim CurField as field
for each curfield in mytdf.fields
curfield.name = trim(curfield.name)
next curfield

set mytdf = nothing

set mydb = nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top