"Field exists" syntax?

M

Maury Markowitz

I'm sure there's some simple syntax for this, but as is too often the case, I
can't find it in the help...

I have to test whether or not a particular rowset has a field. The same code
might be called on any one of a number of tables, half of which have a field
called "entrydate". Is there some way to easily test to see if "entrydate"
exists? If I don't test, UPDATEs fail when I set it.

Maury
 
M

[MVP] S.Clark

To see if the field exists, you can open the recordset, then try to hit the
field. If an error returns then it doesn't exist.

on error resume next
varTest = rs.fields("Fieldname").value
if error <> 0 then
'Field doesn't exist
else
'field does exist
endif
on error goto 0
 
M

Maury Markowitz

To see if the field exists, you can open the recordset, then try to hit the
field. If an error returns then it doesn't exist.

There's no easier way?! This strikes me as astonishingly bizantine.
 
J

John Vinson

There's no easier way?! This strikes me as astonishingly bizantine.

If you're using the Execute method on a querydef object, with
dbFailOnError as a parameter (or with the Fail On Error property of
the query set to true), you can just trap the error there.

John W. Vinson[MVP]
 
Top