I've seen the ! (bang) in several snippets of code. What does it do? What are the rules for using it?
Printable View
I've seen the ! (bang) in several snippets of code. What does it do? What are the rules for using it?
You can use bang to access the field in the recordset
rs!Field
the same you can get as
rs.("Field")
Iouri Boutchkine
[email protected]
please note that the ! in recordset is not a good practise. It is a holdover from dao and ADO is slower to resolve this. In fact, for performance reasons you should always use a with to access multiple fields for example
with rs
.fields(fld1)
.fields(fld2)
end with
an undocumented feature of ADO is to use
with rs
.collect(fld1)
.collect(fld2)
end with
I know, I know. It does not show up in intellisense, try it, it works 30% faster
TANSTAAFL - There ain't no such thing as a free lunch
Actually, the bang is not exclusive to the Recordset object(s). The bang serves as a collection lookup. That is why rs!customerId will not cause an error, but will instead search the Fields collection for a field name customerId (of course this is only an example and your code will error if you use the example with a recordset that does not have this field). Try it yourself:
Dim colTest as new Collection
'
colTest.Add 15, "apples"
colTest.Add 30, "oranges"
colTest.Add 50, "banannas"
'
MsgBox colTest!apples & ", " & colTest!oranges & ", " & colTest!bannanas
As we all know, the Collection object does not have the properties apples, oranges or banannas it is simply looking for a matching item in the collection.
This proves quite deceiving as it appears that the object has a property named apples and it does not.
Hope this is helpful,
Rippin