Does a column exists in the table?

1 post / 0 new
CB's picture
CB
Offline
Joined: 10/19/2012 - 04:54
Does a column exists in the table?

If you want to create a new column in a table just look if it is not still existing...

The fastest way to do that that i know is as followed:

'If you want to create a new column in a table just look if it is not still existing...

sTableName = Dir(Client.Workingdirectory + "tableName.IMD")
Set db = Client.OpenDatabase(sTableName)
Set table = db.TableDef
iFieldCnt = table.count

iCheckColumnExists = 0
For iLoopCounter = 1 To iFieldCnt
Set field = Nothing
Set field = table.GetFieldAt(iLoopCounter)
If field.name = "Name of the maybe new Column" Then
iCheckColumnExists = 1
Exit For
End If
Next iLoopCounter

If CheckColumnExists = 0 Then

'know you can create the new field in the table

End If

cheers,
cb