
referencing a dataset field name
Quote:
>>I recently had an occasion to reference two recordsets, through code in a
form, hwere I had defined a field in each recordset with the same name ( to
assist in documenting, maintaining system, etc).
The problem was that I could not refer to the field name unless I used it
without it being qualified by the recordset name. Is there a way to do this
. . without having different field names in tables?<<
Well, sort of. Whenever you work with any object in DAO (including fields
and recordsets), the parent object has to be in scope.
To get around the inconvenience of declaring and dealing with what feels
like a bunch of extra variables, you write a function that accepts the
parent object as an argument. Within the body of the function, you operate
on the contents of that collection; the name of the parent doesn't matter at
that point.
In your case, you might write a function like this:
Private Function FindDingo(rs as Recordset, sDingo as String) as Boolean
With rs
.FindFirst "[Dingo] Like '" & (sDingo) & "'"
FindDingo = Not .NoMatch
End With
End Function
FindDingo() finds a record in any recordset, regardless of its name. Of
course, the recordset has to have a field called "Dingo" for it to work.
(That's why I made it a private; any procedure with knowledge of outside
structures should usually be isolated...)
Adam