SachAccess
Active member
- Local time
- Today, 04:50
- Joined
- Nov 22, 2021
- Messages
- 409
Hi,
I am trying to rename a field from a table. I have copied below code to perform the task.
The problem here is, in real scenario, I will not be aware about oldName = "Utilitatis|causa|amicitia|est|quaesita|Utilitatis|causa|amicitia"
How do I rename a field without knowing original name of the field.
Can anyone please help me in this.
I am trying to rename a field from a table. I have copied below code to perform the task.
The problem here is, in real scenario, I will not be aware about oldName = "Utilitatis|causa|amicitia|est|quaesita|Utilitatis|causa|amicitia"
How do I rename a field without knowing original name of the field.
Can anyone please help me in this.
Code:
'https://www.access-programmers.co.uk/forums/threads/how-to-automate-renaming-field-names.173179/
Option Compare Database
Sub TableColumnAlter()
Dim counter1 As Long
Dim counter2 As Long
Dim tbl As TableDef
Dim fld As Field
Debug.Print CurrentDb.TableDefs.Count
Table = "NewTable"
oldName = "Utilitatis|causa|amicitia|est|quaesita|Utilitatis|causa|amicitia"
newName = "txtString"
For Each tbl In CurrentDb.TableDefs
If tbl.Name = Table Then
For Each fld In tbl.Fields
If fld.Name = oldName Then
fld.Name = newName
Exit For
End If
Next
Exit For
End If
Next
End Sub