M
Michel Walsh
It can be used where you have more than one parameter to send to your VBA
code behind the form/report and you don't want to relay on global variable
for each of those parameter, and/or when the value to string MAY be a
problem like a double value being truncated to just few decimal when
formatted to a string, or may even be formatted as what your prorgam will
read back as two integers delimited by a coma, if the default regional
setting is using a coma, rather than a dot, as decimal delimiter, to
'encode' the double number into a string. As example, in some European
countries, you can get:
? 5 / 2
2,5
which MAY be read back as two integers rather than a single float.
Using the collection avoid those conversions.
Sure, there is the global variable oCol, but that one is unlikely to collide
with another one of the same name, having a totally different use.
Vanderghast, Access MVP
code behind the form/report and you don't want to relay on global variable
for each of those parameter, and/or when the value to string MAY be a
problem like a double value being truncated to just few decimal when
formatted to a string, or may even be formatted as what your prorgam will
read back as two integers delimited by a coma, if the default regional
setting is using a coma, rather than a dot, as decimal delimiter, to
'encode' the double number into a string. As example, in some European
countries, you can get:
? 5 / 2
2,5
which MAY be read back as two integers rather than a single float.
Using the collection avoid those conversions.
Sure, there is the global variable oCol, but that one is unlikely to collide
with another one of the same name, having a totally different use.
Vanderghast, Access MVP
Hunter57 via AccessMonster.com said:Hi Michel,
That is some very useful information that I look forward to using. Thank
you.
Can you tell me what are some of the possible uses of the collection data
in
the Report or Form?
Best Regards
Pat Wood
http://gainingaccess.com
Michel said:Using Split could be fine, but that assumes you may have to encode your
data
to strings.
Another solution is to use a collection of collections. Have a first
collection, global to the whole application, let us call it oCol.
Next, define all the arguments you want to pass inside a collection:
Dim mCol As New Collection
mCol.Add 33, "zozo"
mCol.Add Now(), "when"
mCol.Add 1 / 3, "oneThird"
here, 3 arguments, zozo, when, and oneThird are added to mCol.
Add the collection to oCol:
If oCol Is Nothing Then Set oCol = New Collection
oCol.Add mCol, "Report1"
And use the name you supplied, in oCol, for your collection as OpenArgs:
DoCmd.OpenReport "Report1", OpenArgs:="Report1"
You can then, inside the report, use:
Dim xCol As Collection
Set xCol = oCol(Me.OpenArgs)
and read each variable you want, like
Dim var As Double
var = xCol("OneThird")
No encoding required, and you can even pass complex objects (which may not
be easy to convert to string, or back from string)
Vanderghast, Access MVP
[quoted text clipped - 50 lines]Hi dch3,.OpenArgs the
same way.