William Benson (VBACreations.Com)
vbacreations at gmail.com
Mon Mar 11 21:55:01 CDT 2013
Here is what I think is a pretty good example of this in a nutshell Arthur: Sub testcol() Dim c1 As Collection Dim c2 As Collection Set c1 = New Collection Set c2 = c1 c1.Add "Bill" Debug.Print "c1 count = " & c1.Count Debug.Print "c2 count = " & c2.Count AddAnItemToC1 c1 Debug.Print "c1 count = " & c1.Count Debug.Print "c2 count = " & c2.Count End Sub Sub AddAnItemToC1(ByRef SomeCol As Collection) SomeCol.Add "Benson" End Sub -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Monday, March 11, 2013 2:13 PM To: Access Developers discussion and problem solving Subject: [AccessD] Any limits on what can be passed as an argument? I suppose that I could whip up a few test harnesses and discover this myself, but hell, why bother in a list full of experts? :) I'm wondering whether virtually *anything* can be passed as an argument. Can I, for example, pass a QueryDef or TableDef? I'm also wondering exactly what happens in the following (pseudo-code) example. <vba> Dim qd as QueryDef Dim qd1 as QueryDef Set qd = QueryDefs("myDef") Set qd1 = qd ... make some changes to qd, such as changing the sql property </vba> 1. Are changes to qd relfected in qd1? (My guess is Yes, that it's just a pointer). 2. If Yes, is there a method such as Clone which would NOT change qd1? 3. Can I pass qd around like any other parameter? And finally, for reasons I won't go into, I declare a qd in the Declarations of a form. In the FormOpen event, I retrieve the particular QueryDef of interest and assign it to qd. In various other form events, I manipulate qd. Then in the spirit of good housekeeping, I close it and set it to Nothing. I've tried this code in both the Close and Unload events, but in each place, Access tells me that there is no object qd. I'm not sure where it's disappearing but it is. I thought that declaring qd at the top would mean that it's alive until I close the form, but apparently I was wrong. I don't really understand what is occurring. Any ideas? Oh, before I close this, if I assign qd to qd1 as above, and then attempt to close qd, am I correct in assuming that this will fail, since there is a reference to qd (qd1)? Finally, if I can pass a QueryDef as a parameter, does this mean that I could pass it to a static function of the standard get/set type, and therefore that it would live until I specifically killed it? (Which reminds me of something I heard in a Q&A session years ago: Q: Do static functions continue to hold their values even if I turn the computer off? A: Well yes, but turning it back on wipes them out. -- Arthur Cell: 647.710.1314 Prediction is difficult, especially of the future. -- Niels Bohr -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com