A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

change label format based on control it is attached to



 
 
Thread Tools Display Modes
  #1  
Old November 6th, 2009, 07:31 PM posted to microsoft.public.access.forms
night_writer
external usenet poster
 
Posts: 12
Default 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  
Old November 6th, 2009, 08:33 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old November 6th, 2009, 09:16 PM posted to microsoft.public.access.forms
night_writer
external usenet poster
 
Posts: 12
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.