How to verify if a field is present in a table

F

felixc36

Hi,

I have a project where i need to verify the existence of a field in a table
before doing the next step.
I know how to crate tables with the Tabledef object and Field object but i
just don t know how t retrieve the fieldname of an existing table.

Anyone can tell me how i can do this?

Thank you in advance

Dan
 
M

Marshall Barton

I have a project where i need to verify the existence of a field in a table
before doing the next step.
I know how to crate tables with the Tabledef object and Field object but i
just don t know how t retrieve the fieldname of an existing table.

Several ways, the one I don't like is to just go ahead and
use the field and use error trapping to detect when it isn't
there.

I think a better method is to iterate through the TableDef's
(or Recordset's) Fields collection and check if it's there>

BolFieldExists = False
For Each fld In tdf.Fields
If fld.name = "thefieldname"
BolFieldExists = True
Exit For
End If
Next fld
If BolFieldExists Then
' ok to proceed
Else
' not there
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top