Is there a way to determine what control I clicked using a global click event. I would like to be able to click a form text box table I created for my access app to enable to enable and unlock it without have a million on click event handlers
Public Sub UnlockTextBoxes(frm As Form)
'frm is the Form you are referring to...
Dim Control As Control
For Each Control In frm.Controls
If TypeOf Control Is TextBox Then
If Control.Name = "MyTextBox" Then
Control.Locked = False
I wrote code like that to find a control by name but what I am trying to do is I have a weekly timecard where all the boxes deailing (Clock in, clock out, lunch start, lunch end, total hours worked) I would like to give th myself the ability to edit the time card incase I made a mistake that does not match up with my company's clockin machine. So their are seven days and under each day I have 6-8 textboxes. If I click on of those textboxes under a certain day it will unlock all the text boxes above and below it so that I can edit the information. I can do this by having a click event for each text box but that would be a whole lot of redundant code for 60+ boxes. How can I have one function that handles all the click events for the form and have it get the active control so that I can determine what day of the week needs to be unlocked for editing
Use an array of controls as in txtDay1(0) to say txtDay1(5) etc. With the above at the 'If Control.Name' you can use 'If Control.Index >0 And Control.Index <6' unlock the textboxes, assuming that you know which day of the week represents which Index number.
This will be about the quickest way of going through all 60 textboxes I think.
that looks to only work if I click a certain box under the day and then it would unlock the reset. I want it so that a user can click any of the boxes under a certain day and it would unlock all the boxes. But each text boxes when clicked calls the same onClick function like this
Private sub handler_Click() ' all textboxes call this automatically
' find out the active control name
but i don't want to do this
Private sub txt_1_Click()
Private sub txt_2_Click()
Private sub txt_3_Click()
public sub handler_event(name as String)
' perform logic here
Sorry for only getting back now - the solution will be a for next loop as in -
Private Sub Text1_Click(Index As Integer)
'Lets say that Text1(0), (6), (12) has the same events -
Dim x As Integer
x = Index
For x = 0 To 10
If x = 0 Or x = 6 Or x = 9 Then
Text1(x).Text = "yeah"
This changes all the textbox text to yeah in 1 go.
Figured out my problem. I had to extend the textbox object with a class module. Inside the class module I had a function that handled onClick events that would search for every object that had the same tag as the active control. Below is my code for the extended class
Private WithEvents TC_txtbox As TextBox
Private day As String
' Set the textbox so that its events will be handled
Public Property Set TextBox(ByVal m_tcTxtBox As access.TextBox)
Set TC_txtbox = m_tcTxtBox
TC_txtbox.OnClick = "[Event Procedure]"
TC_txtbox.Enabled = True
' Handle and onClick event of the
Private Sub TC_txtbox_Click()
' Find out the controls that where clikck
If Not IsNull(day) Then
' Highlight text inside text box
Me.ActiveControl.SelStart = 0
Me.ActiveControl.SelLength = Len(Me.ActiveControl.Text)
' Day has not been set enable text boxes
day = Form_TimeCard.ActiveControl.Tag
Dim ctl As Control
For Each ctl In Form_TimeCard.Controls
If day = ctl.Tag Then
ctl.Enabled = True
ctl.Locked = False
' Handle change event
Private Sub TC_txtbox_Change()
Debug.Print "Shit Changed"
Public Property Get Name() As String
Name = TC_txtbox.Name
I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...