Global click event handler (WithEvents)

I am trying to create a class module that will act as a global handler when someday someone clicks on one of the sixty text fields that I have in my form. Text fields are a temporary table for displaying information in the form of hours, hours, lunch, end, duration, total daily hour for each of the seven days of the week. When someone clicks on one of the boxes for less than a day, all the blocks will be unlocked and turned on so that the user can edit the information in them.

After cleaning the Internet to solve a global click event, I found that I could create a class module that would handle the event without creating a click event for each individual text field that calls a separate function to handle the event. The problem I am facing is that my class module does not seem to be handling my event, and I was wondering if anyone could suggest a solution to my problem. FYI, all of my text fields are both locked and disabled to prevent data corruption. Below is my code:

''# Class module Option Compare Database Option Explicit Public WithEvents TC_txtbox As TextBox ''# Set the textbox so that its events will be handled Public Property Set TextBox(ByVal m_tcTxtBox As TextBox) TC_txtbox = m_tcTxtBox End Property ''# Handle and onClick event of the Private Sub TC_txtbox_Click() ''# Find out the controls that where clikck Debug.Print Form_TimeCard.ActiveControl.Name Dim ctl As Control For Each ctl In access.Forms.Controls Debug.Print ctl.Name Next ctl End Sub 

Form code

 Option Compare Database Option Explicit ''# Global Variables Public clk_inout As Boolean Public settings Public weekDict Public weekOf As Variant Public curDay As Variant Public txtBxCollection As Collection ''# Event Handler for when the form opens Private Sub Form_Open(Cancel As Integer) ''# Configure varaibles Me.TimerInterval = 60000 ''# 10 sec Interval weekOf = getFirstDayofWeek(Date) curDay = Date Set weekDict = CreateObject("Scripting.Dictionary") Set settings = CreateObject("Scripting.Dictionary") Set txtBxCollection = New Collection ''# Load Time Card Data Call initSettings ''# Debug.Print "Work Day Goal " & settings.Item("Work_day_goal_hrs") Call initDict Call initTextBoxEventHandler Debug.Print "Collection count " & txtBxCollection.Count Call loadDates(Date) Call clearDay Call selectDay(Date) Call loadWeeksData(weekOf) Dim ctl As Control Set ctl = weekDict.Item(Weekday(curDay)).Item("In") If IsDate(ctl.Value) And (Not ctl.Value = "") Then Me.but_clk_inout.Caption = "Clock Out" Me.but_lunch.Visible = True clk_inout = False Else Me.but_clk_inout.Caption = "Clock In" Me.but_lunch.Visible = False clk_inout = True End If ''# Debug.Print "Work Day Goal " & settings.Item("Salary") End Sub Public Sub initTextBoxEventHandler() Dim eventHandler As TextBoxEventHandler Set eventHandler = New TextBoxEventHandler Debug.Print "Collection count " & txtBxCollection.Count Set eventHandler.TextBox = Me.txt_F_in txtBxCollection.Add eventHandler Debug.Print "Collection count " & txtBxCollection.Count End Sub 
+4
source share
2 answers

I find out my problem in the class module, where I set the text field, which I forgot to add "TC_txtbox.OnClick = "[Event Procedure]"" VBA will not run the user-defined even handler in my extended text field if [Event Procedure] is not declared In the property of the event that you would like to handle

+1
source

Do you miss Set ? The set of public properties must be

 Public Property Set TextBox(ByVal m_tcTxtBox As TextBox) Set TC_txtbox = m_tcTxtBox ' dont forget the Set! ' End Property 
+1
source

All Articles