|
-
September 14th, 2000, 01:33 PM
#1
Bang
I've seen the ! (bang) in several snippets of code. What does it do? What are the rules for using it?
-
September 14th, 2000, 02:13 PM
#2
Re: Bang
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]
-
September 14th, 2000, 04:58 PM
#3
Re: Bang
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
-
September 15th, 2000, 03:59 PM
#4
Re: Bang
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|