How change all column names in a table design?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table with hundreds of columnns with embedded spaces in the names.
Is there a quick way to change all the spaces to underscores?
 
Unfortunately, that does not help since we are not allowed to install
software on our PCs.
 
The following will rename the fields in the tables. If you need to propagate
these changes through other database objects, though (queries, forms,
reports, macros, modules, data access pages) you're going to have a fairly
major project on your hands ...

Public Sub RenameFields()

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

Set db = CurrentDb
For Each tdf In db.TableDefs
If Mid$(LCase$(tdf.Name), 2, 3) <> "sys" Then
For Each fld In tdf.Fields
If InStr(1, fld.Name, " ") > 0 Then
fld.Name = Replace(fld.Name, " ", "_")
End If
Next fld
End If
Next tdf
MsgBox "Finished"

End Sub
 
Back
Top