Field Exists

  • Thread starter Thread starter Tony Wainwright
  • Start date Start date
T

Tony Wainwright

Hi guys,

I need a function that tells me if a field exists in a TableDef. I'm sure
that this has been written before and I really do not have the time to
re-invent the wheel. Could someone please point me in the right direction
for some code that does this?

Cheers Tony
 
Hi,


( untested )


Public Function IsFieldIn(
ByVal TableName As string,
ByVal FieldName As string) As Boolean

Dim db As Database : Set db=CurrentDb
Dim f As field
For each f In db.TableDefs(TableName).Fields
If f.name = FieldName then
IsFieldIn=true
Exit Function
End if
Next f

Exit Function



Another way would be to try to reach the field, and check if there is an
error:

On Error Resume Next
DMax "FieldName", "TableName"
' not using ( ) simply disregard the result...

IsFieldIn=CBool(0=Err.Number)
On Error ...




Hoping it may help,
Vanderghast, Access MVP
 
Back
Top