greetings,
How can I change the names of the fields in a table to be able to export it in excel. Is there any script that can help me.
Thank you
ortizmario6025@...
Offline
Last seen: 2 days 7 hours ago
Joined: 09/03/2021 - 11:54
The easiest way is to just rename a field in your database and then go to the history and grab the IDEAScript code.
Just curious why you need to change the field names for the Excel database?
Here is an example of changing a character fields name:
I am interested in changing it, since the table comes with a name that the end user does not know how to interpret well, therefore I have to export it to excel with a name that is familiar in order to interpret it.
That makes perfect sense, thanks for letting me know. If you want to do multiple fields you can do something like this:
You need to run the PerformTask after each one, if you don't there is a bug and the last field is always really wide for some reason. I don't think they have fixed it because we have the work around.
You can also do this as a loop to save on coding if you want.
Good
If multiple fields are renamed I would prefer an extra Sub or Function like that:
Sub RenameField(sOldField As String, sNewName As String)
Set db = Client.CurrentDatabase()
Set task = db.TableManagement
Set oOldField = db.TableDef.GetField(sOldField)
Set field = db.TableDef.NewField
field.Name = sNewName
field.Description = oOldField.Description
field.Type = oOldField.Type
If oOldField.Type = WI_CHAR_FIELD Or oOldField.Type = WI_VIRT_CHAR Then
field.Length = oOldField.Length
field.Equation = oOldField.Equation
ElseIf oOldField.Type = WI_NUM_FIELD Or oOldField.Type = WI_VIRT_NUM Then
field.Decimals = oOldField.Decimals
field.Equation = oOldField.Equation
ElseIf oOldField.Type = WI_DATE_FIELD Or oOldField.Type = WI_VIRT_DATE Then
field.Length = oOldField.Length
field.Equation = oOldField.Equation
End If
task.ReplaceField oOldField.Name, field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing
End Sub
thanks to both