We help IT Professionals succeed at work.
Get Started

MS Access global event handler

Nick67
Nick67 asked
on
5,035 Views
Last Modified: 2013-11-27
This concerns MS Access 2003 VBA.
I have 336 textboxes on a form.  I want them all to respond to a double-click event in the same fashion--and perhaps in the future to other events.  I'd prefer not to create 336 separate events in the form's module, one for each textbox.  Sample code for this type of solution, for Excel, can be found at:
http://j-walk.com/ss/excel/tips/tip44.htm

I cannot get my adapted code to work in Access.  It compiles without errors--but the double-click event does not get handled.  What am I doing wrong?  Code to follow:

in a class module named clsTextboxGroup
'clsTextboxGroup
'-------------------------------------------------------------------
Option Compare Database
Option Explicit
Public WithEvents TextBoxGroup As Access.TextBox

Private Sub TextboxGroup_DblClick(Cancel As Integer)
    MsgBox "Hello from " & TextBoxGroup.Name
    'I will put in more substantive events after I get this working
End Sub
'-------------------------------------------------

Open in new window


In the module of the form with the 336 textboxes

'the form's module
Option Compare Database
Option Explicit
Dim MyTextboxes() As New clsTextBoxGroup

Private Sub Form_Load()
Call InitMyTextboxEvents
end sub
'---------------------------------------------------
Public Sub InitMyTextboxEvents()
Dim TextboxCount As Integer
Dim ctl As Control

'   Create the Textbox Objects
TextboxCount = 0
For Each ctl In Forms("frmWeek").Detail.Controls
    If ctl.ControlType = acTextBox Then
        If ctl.Name Like "*booking*" Then 'snag only the required textbox controls
            TextboxCount = TextboxCount + 1
            ReDim Preserve MyTextboxes(1 To TextboxCount)
           Set MyTextboxes(TextboxCount).TextBoxGroup = ctl
        End If
    End If
Next ctl

end sub

Open in new window

Comment
Watch Question
President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
Unlock 2 Answers and 39 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE