Unkown Cls/Collection Holding An Event

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 one could use parameters with the function & I'm wrong here.
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 atm would be in the form to have 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...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom