Unkown Cls/Collection Holding An Event (2 Viewers)

Then, if you have a cTaxEngineFederal class, it might look like...
Code:
Private stg_ As Object
Private year_ As Long
Private fedTax_ As Currency
Private prvTax_ As Currency

Sub Init(Year As Long, Province As String)
    year_ = Year
    Set stg_ = GetTaxStrategy("Calc" & Province & "Tax")
End Sub

Sub CalcTotalTax()
    fedTax_ = CalcFedTax
    prvTax_ = stg_.Execute(fedTax_)
    
    MsgBox "Total Tax is " & fedTax_ + prvTax_
End Sub

Private Function CalcFedTax() As Currency
    ' returns federal tax
End Function
So this allows for runtime selection of an appropriate provincial tax calc strategy based on runtime data. And it keeps your code really tidy because each provincial strategy is discretely encapsulated in snap-in class expressly and independently developed and tested.
 
No, your first function does not create an instance. Somewhere you need to use the New keyword to create an instance. Your first function will raise an error because GetStrategy is not an object yet.
 
I wrapped all textboxes in my frm.description in a cls to assign a right-click CommandBar menu to all textboxes to save me doing it individually. Then added them to user-defined collection so the right-click event would stay around.

The trouble is I was playing around with the cls names & collection names I now no longer know what it's been assigned to; and if it is only a single instance.

How do i list all collections belonging to the form/ wrapped class & tidy up my form? Unsure of the name of the associated cls/ collection.
Somewhere in the CurrentProject/ CurrentDb I have rogue instances of a Collection and or Classes which I need to find. I thought MSys would help me out but they only show Access standard objects I think.

I would've thought there would be a way to list all user-declared Collections & Classes.

Have you tried using the object browser?

ObjectBrowserVBA.Collection.png


You can also query the Name field in the MsysObjects table for Types 1 and 3 objects:

Code:
SELECT vTbl.ObjectType, Count(vTbl.ID) AS CountOfID
FROM (SELECT Switch(Type=-32768,"Forms"
                   ,Type=-32766,"Macros"
                   ,Type=-32764,"Reports"
                   ,Type=-32761,"Modules"
                   ,Type=-32756,"Data Access Page"
                   ,Type In (1,4,6),"Tables (Inc. System Tbls)"
                   ,Type=5,"Queries"
                   ,Type=3,"Containers"
                   ,1=1,"Other Stuff Managed by Access") AS ObjectType, ID
      FROM MSysObjects
      WHERE Left(Name,1)<>"~") AS vTbl
GROUP BY vTbl.ObjectType;
 
Last edited:
I didn't spot Containers, so thanks for that. I have a limited understanding so have found the Object Browser to be most confusing; unable to find logic to it. Yes, Objects, Methods, Properties, Classes... but up until recently I've struggled to find the consistency in VBA. This topic is a big-step in getting a deeper understanding so I'm most grateful.

Trying to get a deeper understanding of memory leaks... I found the following tool; specific for Access to see the allocation of memory which users may find interesting:


1754823535357.png
 
I didn't spot Containers, so thanks for that.

Well, container types are not really applicable to what you're looking for since container collection and container objects are part of the DAO object model. The names Microsoft chose for container collection and container objects is ambiguous, confusing, and poorly documented. Nothing new with MS.

I have a limited understanding so have found the Object Browser to be most confusing; unable to find logic to it. Yes, Objects, Methods, Properties, Classes... but up until recently I've struggled to find the consistency in VBA. This topic is a big-step in getting a deeper understanding so I'm most grateful.

Trying to get a deeper understanding of memory leaks... I found the following tool; specific for Access to see the allocation of memory which users may find interesting:


For finding and analyzing memory leaks I use a tool named Process Explorer,
available for free at: https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer

AccessMemoryLeaks.png
 
Last edited:
Coolio, to clarify @MajP & @MarkK kindly identified the issue which was not instantiating the cls at each iteration. I've abused their kindness a little (sorry guys) by extending the thread a little & we've gotten into advanced decoupling; which I am extremely grateful for. This goes a massive way forward into understanding moreso how Access works & a better chance of being able to understand & benefit from the Object Inspector a bit more & becoming a more capable developer. At the moment I'm just a donkey 🐴, with the dream of one day becoming a fine stallion 🐎🏇🎠.
:ROFLMAO: :ROFLMAO:
 
I've abused their kindness
@dalski Not at all. It is a pleasure to find someone as curious and interested as you. I get a huge kick out of coming to understand new code patterns, so having an exchange with someone who shares that pleasure is itself a pleasure.
Cheers,
Mark
 

Users who are viewing this thread

Back
Top Bottom