rename fields programmatically

  • Thread starter Thread starter mcnewsxp
  • Start date Start date
M

mcnewsxp

is there a quick way to rename fields in tables?
for example replace spaces with an underscore.

then is there a quick way to run through queries and forms that reference
these fields and fix them.

either queries, code or 3rd party tool.

thanks much!
mcnewsxp
 
Using DAO (so if you're using Access 2000 or newer, you'll have to make sure
you've set a reference to DAO):

Dim dbCurr As Database
Dim tdfCurr As TableDef
Dim fldCurr As DAO.Field

Set dbCurr = CurrentDb()
For Each tdfCurr In dbCurr.TableDefs
For Each fldCurr In tdfCurr.Fields
fldCurr.Name = Replace(fldCurr.Name, " ", "_")
Next fldCurr
Next tdfCurr

Set fldCurr = Nothing
Set tdfCurr = Nothing
Set dbCurr = Nothing

Actually, if you're NOT using Access 2000 or newer, you're going to have to
write your own Replace function, as it wasn't introduced in Access until
Access 2000. The code in http://www.mvps.org/access/strings/str0004.htm at
"The Access Web" is one way to do it.
 
beautiful!
thanks!

know of any tools that can do same for queries and forms? or at least find
things that aren't linked up correctly?
 
Back
Top