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

Help renaming multiple table fields in VBA

Status
Not open for further replies.

startup

Technical User
May 22, 2002
42
US
I have a table which which is created from an Excel spreadsheet I import and has certain field names that come over from the spreadsheet. Can someone help me figure out how to change these multiple field names in VBA?

This is what the field names are after I import:

Quiz1, Quiz2, Quiz3, Exam1, Exam2 ... etc (The number of columns is irrelevant, there may only be two or there may be 20)

What I need to do is to add a certain string to the end of each field name, in this case "Out Of Grade", so the resulting field names would be:

Quiz1Out of Grade, Quiz2Out of Grade, Quiz3Out of Grade, Exam1Out of Grade, Exam2Out of Grade, etc.

I have figured out how to change an individual name if I know the name in advance. But in my case I don't know what the names will be until they are imported.

Thanks for any help
Rico
 
Have you tried to play with the DAO.Fields collection of the DAO.TableDef object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
After posting I figured out a method that works for me. Here's the code I used:

Dim MyDb As Database
Set MyDb = CurrentDb
Dim MyTdf As TableDef
Set MyTdf = MyDb.TableDefs("ConvertTable")

Dim counter As Integer
For counter = 0 To MyTdf.Fields.Count - 1
MyTdf.Fields(counter).Name = MyTdf.Fields.Name & "Out Of Grade"
Next counter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top