Re: Change Field Name in Table
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Thu, 27 Apr 2006 23:08:18 -0500
GrandMaMa wrote:
We have a new software package from a vendor where we must change the Field[]
Name in a Table.
Two days ago we submitted this and never got the problem resolved. Because
of the field names (Example is HMDA - Interest (numeric)) we cannot use a
query to recreate the new table. The Query will take the above field name
and convert it to (HMDA-Interest(numeric)). This seems to be a problem with
Access 2002 and 2004 that we did not have with Access 2000.
The software firm is shocked that we even were able to delete the original
table because they used assembler to secure it.
Here is the code at this minute!
Dim TableName As String
Dim db As DAO.Database
Dim rst As Recordset
Dim tdf As TableDef
Dim fld As Field
Dim cnt As Byte
Set db = CurrentDb
With db
For Each tdf In .TableDefs
If tdf.Name = "AlphaErrors" Then
TableName = Left(tdf.Name, 11)
db.TableDefs!TableName.Fields![NoFive].Name =
"NoSix" ' Here is the Error
The error is Item not found in this collection. Do not know if I have a[]
Microsoft problem or if my syntax is in-correct.
In this case, you are using the variable TableName and not
the name of the table so, yes, it is a syntax issue. In my
earlier post, is used tablename as a placeholder for the
real table name (which I did not know then) and fogot to
explain that you should replace it with the real name.
To use a variable with the table name as its value (as you
tried above), you need drop the bang and enclose it in
parenthesis:
db.TableDefs(TableName).Fields![NoFive].Name = "NoSix"
OTOH, since you know the name of the table, you can use it
directly:
db.TableDefs!AlphaErrors.Fields![NoFive].Name = "NoSix"
Either way should work.
BTW, there is no need for the For Each loop unless there is
a chance that the table might not exist.
--
Marsh
MVP [MS Access]
.
- Follow-Ups:
- Re: Change Field Name in Table
- From: GrandMaMa
- Re: Change Field Name in Table
- Prev by Date: Re: How to refer to the 2nd record of a subform ?
- Next by Date: Re: Using a form control to change another form control
- Previous by thread: Re: Change Field Name in Table
- Next by thread: Re: Change Field Name in Table
- Index(es):
Relevant Pages
|
Loading