If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
change label format based on control it is attached to
I hve a form that has checkboxes for all 50 states. Because individual
checks are hard for the user to see, I color the label of the field when the box is checked. When the form is open and a new a box is checked or unchecked, I run the following code for each checkbox on the AfterUpdate event: Private Sub chkAK_AfterUpdate() If Me.chkAK.Value = True Then With Me.chkAK_Label .BackStyle = 1 .BackColor = 16762052 End With Else With Me.chkAK_Label .BackStyle = 0 .BackColor = -2147483633 End With End If End Sub However, I also want to check the condition of each box and color the label appropriately when the OnCurrent event occurs for the form itself. Right now, I am actually doing a "call" for every individual checkbox AfterUpdate event and it gets the job done, but seems excessively heavy handed. I am thinking that some kind of For / Next for each control would be much better, but I can't figure out how to go from testing the checkbox to identifying the label that is attached to it. Because all of my controls are named similarly, I could actually create the label name from the checkbox name ("chk" & right(checkbox.Name,2) & "_Label"), but that's a string. I don't know how to translate that to refer to the label control so I can change the formatting on the label. Maybe I'm trying to make this too difficult. Would appreciate any creative solutions anyone cares to offer! Alice |
#2
|
|||
|
|||
change label format based on control it is attached to
Me.Controls("chk" & Right(checkbox.Name,2) & "_Label")
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "night_writer" wrote in message ... I hve a form that has checkboxes for all 50 states. Because individual checks are hard for the user to see, I color the label of the field when the box is checked. When the form is open and a new a box is checked or unchecked, I run the following code for each checkbox on the AfterUpdate event: Private Sub chkAK_AfterUpdate() If Me.chkAK.Value = True Then With Me.chkAK_Label .BackStyle = 1 .BackColor = 16762052 End With Else With Me.chkAK_Label .BackStyle = 0 .BackColor = -2147483633 End With End If End Sub However, I also want to check the condition of each box and color the label appropriately when the OnCurrent event occurs for the form itself. Right now, I am actually doing a "call" for every individual checkbox AfterUpdate event and it gets the job done, but seems excessively heavy handed. I am thinking that some kind of For / Next for each control would be much better, but I can't figure out how to go from testing the checkbox to identifying the label that is attached to it. Because all of my controls are named similarly, I could actually create the label name from the checkbox name ("chk" & right(checkbox.Name,2) & "_Label"), but that's a string. I don't know how to translate that to refer to the label control so I can change the formatting on the label. Maybe I'm trying to make this too difficult. Would appreciate any creative solutions anyone cares to offer! Alice |
#3
|
|||
|
|||
change label format based on control it is attached to
On Nov 6, 1:33*pm, "Douglas J. Steele"
wrote: Me.Controls("chk" & Right(checkbox.Name,2) & "_Label") -- Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele (no e-mails, please!) "night_writer" wrote in message ... I hve a form that has checkboxes for all 50 states. Because individual checks are hard for the user to see, I color the label of the field when the box is checked. When the form is open and a new a box is checked or unchecked, I run the following code for each checkbox on the AfterUpdate event: Private Sub chkAK_AfterUpdate() If Me.chkAK.Value = True Then With Me.chkAK_Label * *.BackStyle = 1 * *.BackColor = 16762052 End With Else With Me.chkAK_Label * *.BackStyle = 0 * *.BackColor = -2147483633 End With End If End Sub However, I also want to check the condition of each box and color the label appropriately when the OnCurrent event occurs for the form itself. Right now, I am actually doing a "call" for every individual checkbox AfterUpdate event and it gets the job done, but seems excessively heavy handed. I am thinking *that some kind of For / Next for each control would be much better, but I can't figure out how to go from testing the checkbox to identifying the label that is attached to it. Because all of my controls are named similarly, I could actually create the label name from the checkbox name ("chk" & right(checkbox.Name,2) & "_Label"), but that's a string. I don't know how to translate that to refer to the label control so I can change the formatting on the label. Maybe I'm trying to make this too difficult. Would appreciate any creative solutions anyone cares to offer! Alice- Hide quoted text - - Show quoted text - Thank you very much. This did the trick! Here is my final code, just in case anyone else would find it useful. (I tagged my state checkboxes "state" so I wouldn't be checking any other checkboxes on the form): Dim ctl As Control For Each ctl In Me.Controls If ctl.Tag = "State" Then Select Case ctl.ControlType Case acCheckBox If ctl.Value = -1 Then With Me.Controls("chk" & Right(ctl.Name, 2) & "_Label") .BackStyle = 1 .BackColor = 16762052 End With Else With Me.Controls("chk" & Right(ctl.Name, 2) & "_Label") .BackStyle = 0 .BackColor = -2147483633 End With End If End Select End If Next ctl Alice |
Thread Tools | |
Display Modes | |
|
|