Function FieldExists(strField as string, varIn as Variant) as Boolean
on error resume next
Dim fld as DAO.Field
FieldExists=False
for each fld in varIn.Fields
if fld.name=strfield then
FieldExists=True
end if
next fld
End Function.
I'm writing it freehand, so excuse any mistakes please! The function takes a field name and a variant as parameters. The variant could be a tabledef, a recordset or a querydef.
Dim td as tabledef
set td=currentdb.tabledefs("tblData"
msgbox Fieldexists("Field1",td)
HTH
Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
I took your code out of the function and it doesn't seem to work. I get the "Object Invalid or no longer set" error.
Here's how I used your code.
Dim td As TableDef
dim fld As DAO.field
FieldExits = False
Set td = CurrentDb,TableDefs("actsrec" 'It stops here!!
For Each fld in td.fields
If fld.Name = "balance then
FieldExists = True
End if
Next fld
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.