controlador de eventos de clic global (WithEvents)
Estoy tratando de crear un módulo de clase que actúe como un controlador global para cuando alguien haga clic en uno de los sesenta cuadros de texto que tengo en mi formulario. Los cuadros de texto representan una tarjeta de tiempo para la semana que muestra información como entrada, salida, inicio, finalización, duración del almuerzo, total de horas diarias en cada uno de los siete días de la semana. Cuando alguien hace clic en cualquiera de los cuadros en un día, todos los cuadros se desbloquearán y habilitarán para que el usuario pueda editar la información en ellos.
Después de buscar en la web una solución de un evento de clic global, descubrí que podía crear un módulo de clase que manejaría el evento sin crear un evento de clic para cada cuadro de texto que llama a una función separada para manejar el evento. El problema que tengo es que mi módulo de clase no parece estar manejando mi evento y me preguntaba si alguien podría sugerir una solución a mi problema. Para su información, todos mis cuadros de texto y bloqueado y deshabilitado para evitar la corrupción de datos. Abajo está mi código:
''# 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
Código de formulario
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