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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Field Names Using VBA 1

Status
Not open for further replies.

JcTon

MIS
Oct 26, 2007
16
US
Imported text file into Access table and field names did not import correctly. (Field names are in row 30!)

Currently, field names are field1, field2, field3, etc.

I assume that I can modify the code below to not only change the field names but also to specify the data type in the field. Is this correct?

Also, during the import of the text file, I was not prompted with the dialog on whether to specify the first row as column field name. Any known reasons why I was not prompted?


Public Sub ChangeFieldName(TableName As String, OldName As String, NewName As String)
Dim db As DAO.Database, tdf As DAO.TableDef

Set db = CurrentDb
Set tdf = db.TableDefs(TableName)

tdf(field1).Name = CustomerName
tdf(field2).Name = CustomerAddress
tdf(field3).Name = CustomerPhone
Set tdf = Nothing
Set db = Nothing
End Sub

 
My gut tells me that the Name property for a field is read only unless perhaps it is designed first which I have not researched.

Perhaps an easier solution would be to use the import specification and docmd.transfertext or build a correctly formatted table and then import to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top