cinnie said:
hi
I''ve borrowed some code that works fine, but I have a question. What
does
the '(0)' at the end of the following line mean? I can't find the answer
in
'help'.
Div = CurrentDb.OpenRecordset(strSQL)(0)
Thankyou
It means "return the first field in the Recordset's Fields collection." You
see, OpenRecordset returns a Recordset object. A Recordset object's default
collection is its Fields collection. The fields in this collection are
numbered starting with 0, so field 0 is the first field in the collection.
By putting parentheses -- () -- after the reference to the recordset, the
code is saying, "I want to look in a collection", and since it doesn't
specify which collection, the default Fields collection is used. By putting
0 inside the parentheses -- (0) -- the code is saying, "give me field 0 (the
first field) in this collection."
The statement is equivalent to the more long-winded,
Div = CurrentDb.OpenRecordset(strSQL).Fields(0)
Note, by the way, that since no object variable is set to the recordset
itself, the recordset object will go out of scope and be destroyed
immediately after this line is executed. The code is trusting that the
recordset will be closed properly as part of its disposal routine. I'm a
little less trusting, myself, and would do the same thing like this:
With CurrentDb.OpenRecordset(strSQL)
Div = .Fields(0)
.Close
End With
But assuming all goes well, it has the same effect.