Home Access an Collection within a form via VBA out of a Class-module
Reply: 0

Access an Collection within a form via VBA out of a Class-module

user46850
1#
user46850 Published in September 19, 2018, 3:18 am

I just like to reorder the VBA of a bunch of Forms in Access, doing all nearly the same. So I created a class clsPopup and I just want to pass some collections out of all this Forms into the class, so I can access their entries over there or in there or how ever.

I could pass the Form-element of the Popup to the class as I created a sub named Load in clsPopup like

Dim m_frm As Form  

sub Load(frm As Form)
    Set m_frm = frm
    debug.print m_frm.colSp("Name")
end sub

In the Form I tried

Dim m_clsPopup As clsPopup
Dim colSp As Collection

sub Form_Load()
    Set m_clsPopup = New clsPopup
    Set colSp = New Collection

    colSp.Add "SomeString", "Name"
    m_clsPopup.Load Me.Form

end sub

At this point I got the 2465 Runtime error in the line of m_clsPopup.Load Me.Form.

My main idea is, to just collect all the needed data within the Forms as collections and than I easily could work with them in the class.

Of course I thought of arrays, but collections seems so much more handy and I could avoid some terrible indexing.

Ahh, and it needs to work in Access 2010. Might that be the problem?

I feel like just a tiny pice of code is missing. Could anyone help to create nice code out of a masterpiece of redundancy?

share|improve this question
  • Error 91 isn't "missing object or can't access it", error 91 is "Object variable or With block variable not set", and what this means is that you haven't Set the object variable. m_frm is an object variable, so the Set keyword is required to assign it. The Load procedure needs to do Set m_frm = frm. – Mathieu Guindon Jan 12 at 21:12
  • Then, if the signature for Load is Load(OneSingleParameter), then you get error 5 "Invalid procedure call or argument" with clsPopup.Load arg1, arg2, because clsPopup.Load has one parameter and you're passing two. That said I would strongly advise against naming an object variable the same name as its type/class. – Mathieu Guindon Jan 12 at 21:17
  • @Mat's Mug Thx for these two comments, I fixed the first issue and refreshed the question. – Wien.MC Jan 12 at 22:27
  • @Mat's Mug and you are right, I shoud have mentioned, that indee I changed the Load-Function, as it now can get two input variable: Public Sub Load(frm As Form, colSp as Collection), but still I get the error 5, as if the collection is not acceped as a valid input. How ever, I even checked Public Sub Load(frm As Form, colSp as Variant) with m_clsPopup(Me.Form, colSP), still error 5. – Wien.MC Jan 12 at 22:33
  • Your question makes no sense. Please keep in mind that readers can't see your screen. You need to edit your post and clarify what the specific issue is, and provide a Minimal, Complete, and Verifiable example that reproduces that problem. – Mathieu Guindon Jan 12 at 22:36

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
 
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48232164%2faccess-an-collection-within-a-form-via-vba-out-of-a-class-module%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged vba forms class collections or ask your own question.

StackExchange.ready(function(){$.get('/posts/48232164/ivc/a6b2');});
StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|vba|forms|class|collections|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344106 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO