Unkown Cls/Collection Holding An Event (3 Viewers)

Thanks guys, learning a lot. I'm new to classes & this is probably a bit much for me at this early stage but I think if I can get a good understanding of them that's 90% of VBA (OOP) & less likely to come across issues later. It's interesting no matter how much you read you come across issues (MSN seriously lacking).

A problem here @MarkK pointed out that I was using a Form_FrmName reference; which can cause problems. I thought it would be nice to reference the form directly as it's object; allowing auto-update on it's name should i change it. But was unaware that if the form was not found it would then create a reference of it. He also kindly pointed out that an external reference outside the class to a procedure was the main issue. Obviously only Mark got handed the db so no one else could have been aware of this.

My original goal here was to assign a right-click event raiser globally to controls in the Detail section of a form & have a single event/ function/ whatever handle them. A way of assigning an ObjVar_ObjVarEvent of the user's type. The benefit being I may add/ delete controls... later to this frm & this coding pattern would save me in the future (more importantly I'm trying to learn). Was tyring to use classes to learn & get the most of out the exercise as I have little experience with classes.

Disregarding classes for a moment, I was thinking of using a function to handle multiple events from @MajP 's fine https://www.access-programmers.co.u...-you-need-to-know-about-access-events.308963/ in the form directly. But I cannot see how one could pass an argument (Button) of the MouseUp event if one was to assign a custom function? Seems that the function name must be a literal; "=fnName()" with a set of parentheses. Cannot handle concatenation, even from VBA. Be great if it is possible to use parameters with the function when assigning the function to handle multiple events.
I just discovered that there is a:
Code:
Private Sub Detail_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
but suprisingly does not seem to work.

The perfect solution would be if VBA supported below in pseudo code:

SubFrm:
mctrl as Control
Code:
Private Sub Form_Load:
  Dim mctrlAs Control
  For Each ctrl In Me.Detail.Controls
    If mctrl.ControlType = acTextBox Then
      mctrl.OnMouseUp = "[Event Procedure]"
    End If
  Next ctrl
End Sub

Private Sub mctrl_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbKeyRButton Then
    MsgBox "Honour the coders"
End Sub

It's quite difficult to see when to use a class over the data in tables... My main take at this point is they are of benefit in forms in grouping things... Done a few tutorials relating to data... but I think it's hard for a user to comprehend when a class prevails/ complements over the schema design... double-work as you've now got data in classes & data in tables which require updating...

It seems the options are:
  1. You separate the object itself as a class (object) & the object handler as another class (strategy). You merge them together & refer to the clsStrategy.FunctionName.
  2. You use a Collection Class.
 
Last edited:
I previously said you can also CRUD tag properties in vba code. Me thinks it's actually faster to use them than having to write code to create and maintain classes. But I'm not knocking that. If you prefer creating classes, so be it. I have a checklist I use when creating new apps.
I am sorry but this is 10 times funnier, because it is two completely unrelated topics. This is such a complete "apples and oranges" comparison that it makes no sense at all. Have you not been following the conversation? Explain again how the tag property will replace the capability of a class to
1. Trap events of multiple controls
2. Extend the properties of those controls
3. Encapsulate multiple functionality to avoid writing new code
4. Raise custom events
5. Allow to define the functionality when an event occurs

Using the tag property to group controls is a pretty well known and well used, but not really related to the conversation. Some times you need to read the room. Just saying.
 
I am sorry but this is 10 times funnier, because it is two completely unrelated topics. This is such a complete "apples and oranges" comparison that it makes no sense at all. Have you not been following the conversation? Explain again how the tag property will replace the capability of a class to
1. Trap events of multiple controls
2. Extend the properties of those controls
3. Encapsulate multiple functionality to avoid writing new code
4. Raise custom events
5. Allow to define the functionality when an event occurs

Using the tag property to group controls is a pretty well known and well used, but not really related to the conversation. Some times you need to read the room. Just saying.
I mentioned tag properties because it'similar to what the OP wants to accomplish with his global right click controls.
 

Users who are viewing this thread

Back
Top Bottom