Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have a userform with 8 labels and 8 textboxes. The textboxes follow the same naming convention: tb_s#_reline, where # is the respective textbox number (1-8)
Each of the 8 textboxes have the same exit event code, differing only in their interaction with other controls associated with the same number (ie tb_s7_reline.exit code applies a property value to label7).
In an effort to not have to repeat the same code 8 different times for each of the 8 exit exents, is it possible to code the exit events to code in a standard module? Here is my logic, I just need to know if it's possible, and some guidance as to how to refer to the controls from within the module.
This code is conceptual only, just to kind of share my thoughts.
This is where I am most uncertain...
In my tinkering, I get an "object required" error when referencing the .controls. If I add 'Me' to .controls, I get an "Invalid use of Me keyword"
I would Google but I'm unsure of the best search terms.
Each of the 8 textboxes have the same exit event code, differing only in their interaction with other controls associated with the same number (ie tb_s7_reline.exit code applies a property value to label7).
In an effort to not have to repeat the same code 8 different times for each of the 8 exit exents, is it possible to code the exit events to code in a standard module? Here is my logic, I just need to know if it's possible, and some guidance as to how to refer to the controls from within the module.
This code is conceptual only, just to kind of share my thoughts.
Code:
Public userform_test as object 'the userform object
Public frmno as long 'the unique control ID (1-8)
Set userform_test = userform1
Code:
Private Sub cbx_s1_rln_Click()
frmno = 1
cbx_reline frmno
End Sub
This is where I am most uncertain...
Code:
Sub cbx_reline (frmno as long)
With userform_test
If .controls("tb_s" & frmno & "_reline").Value = "" Then
.controls("tb_s" & frmno & "_reline").backcolor = vbred
.controls("tb_s" & frmno & "_reline").enabled = false
.controls("label" & frmno).enabled = false
End If
End With
End Sub
In my tinkering, I get an "object required" error when referencing the .controls. If I add 'Me' to .controls, I get an "Invalid use of Me keyword"
I would Google but I'm unsure of the best search terms.