Desiring to shorten my code and prevent having to create multiple OnClick events for several similar CommandButtons, I decided to try and implement a custom class. I created a new Class Module:
clsButtonGroup
...and in the module of my main form where the buttons reside I have:Code:Option Compare Database Option Explicit Public WithEvents ButtonGroup As CommandButton Private Sub ButtonGroup_Click() MsgBox "Button " & ButtonGroup.Name & " was clicked!" End Sub
When I launch the form in Form View everything seems to work fine. When I switch to Design View however, I get an EMET error (EMET detected DEP mitigation & Microsoft Access has stopped working) and Access crashes to desktop. When I comment out all the code in the Form_Load event section and repeat the process, Access is fine (no crash). I'm totally new to custom classes so I'm hoping this is just a coding mistake. Any help is much appreciated. Thanks!Code:Option Compare Database Option Explicit Dim Buttons() As New clsButtonGroup Private Sub Form_Load() 'CREATE BUTTON GROUP Dim btnCount As Integer Dim ctl As Control btnCount = 0 For Each ctl In Me.Controls If TypeName(ctl) = "CommandButton" Then If ctl.Tag = "filter" Then btnCount = btnCount + 1 ReDim Preserve Buttons(1 To btnCount) Set Buttons(btnCount).ButtonGroup = ctl End If End If Next ctl End Sub




Reply With Quote
