Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blinking Label on Subform conditional to Mainfrm Control

Status
Not open for further replies.

catrey

Technical User
Feb 12, 2009
15
US
I have a subform fsubGuardianhship that has on it textbox ckGuardProof with a two-line label that uses two label controls: a transparent control LblProofGd1 containing the words "Proof of Guardianship", and a second label LblProofGd2 that provides a background and the second line of text, "in file?"

I want the text to be dark red and want LblProofGd to blink ONLY when ckGuardProof is not checked (that is, = 0 which is to say, 'no' or 'false') AND a toggle button on the main form TogBHasGuard, is selected (that is, = -1 which is to say, 'yes' or 'true').

I have tried writing the code a gajillion different ways and can get one set of conditions to work (for example, the effects I want 'If ckGuardProof = -1 AND TogBHasGuard = -1'), but when I add other conditions nothing works right and/or I do not get the correct behavior when, say, the ckGuardProof box is unchecked (it should turn from green to red and start blinking if the TogBHasBuard is -1; not-blinking if TogBHasGuard is 0 or null).

Here's the most step-by-step version of code I've tried.
colors are represented as follows:

14013951 is the pink background color of LblProofGd2 (if the text in lblProofGd1 is changed to this color it appears to turn off because it's the same color as background)
106 = dark red
18432 = dark green

First, for the blinking behavior, the On Timer property of the subform (in the fsubGuardianship module) is set as follows:

Private Sub Form_Timer()
With LblProofGd1
.ForeColor = (IIf(.ForeColor = 14013951, 106, 14013951))
End With
End Sub

Then in the AfterUpdate event of the checkbox ckGuardProof:

Private Sub ckGuardProof_AfterUpdate()

'This should cause 'Proof of Guardianship in File?' label to blink if
'main form Has-Guardian toggle is ON (yes) and subform 'Proof of
'Guardianship in File?' is NOT checked (false)
If Len(Trim(Nz(Me.ckGuardProof))) = 0 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
Me.LblProofGd1.ForeColor = 14013951
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd2.Caption = "in file?"
Me.TimerInterval = 500
End If
'When both subform 'Proof of Guardianship in file?' box is checked and main form 'Has
'Guardian' toggle is ON (yes), this should cause 'Proof in file?' label to turn dark
'green, remove the question mark from the label, and stop blinking behavior
If Me.ckGuardProof = -1 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
Me.LblProofGd1.ForeColor = 18432
Me.LblProofGd2.ForeColor = 18432
Me.LblProofGd2.Caption = "in file"
Me.TimerInterval = 0
End If
'When both subform 'Proof of Guardianship in file?' box is NOT checked and main form
''Has Guardian' toggle NOT selected (false), this should TURN OFF blinking and
'cause 'Proof in file?' font to turn dark red as well as restore question mark.
If Len(Trim(Nz(Me.ckGuardProof))) = 0 And Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd2.Caption = "in file?"
Me.TimerInterval = 0
End If
'If 'Proof of Guardianship in File?' box IS checked (yes) but 'Has Guardian' toggle on main
'form is NOT checked (false), makes subform label dark green, removes checkmark, and label
'stops blinking, but launches message box prompting user to change the 'Has Guardian' toggle
'to 'yes'.
If Me.ckGuardProof = -1 And Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
Me.LblProofGd1.ForeColor = 18432
Me.LblProofGd2.ForeColor = 18432
Me.LblProofGd2.Caption = "in file"
Me.TimerInterval = 0
myExclamation ("'Has Guardian' toggle button at right" & vbNewLine & _
"on main form Is not pressed." & vbNewLine & vbNewLine & _
"Please do so if there is Guardian.")
End If
If Forms!frmClientInfoEnter.TogBHasGuard = -1 And Me.ckGuardProof = -1 Then
End If

End Sub

Here's another way I've tried writing the If/Then statements:

If Len(Trim(Nz(Me.ckGuardProof))) = 0 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
Me.LblProofGd1.ForeColor = 14013951
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd2.Caption = "in file?"
Me.TimerInterval = 500
ElseIf Me.chGuardProof = -1 and Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
Me.LblProofGd1.ForeColor = 18432
Me.LblProofGd2.ForeColor = 18432
Me.LblProofGd2.Caption = "in file"
Me.TimerInterval = 0
ElseIf Len(Trim(Nz(Me.ckGuardProof))) = 0 And Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd1.ForeColor = 106
Me.LblProofGd2.Caption = "in file?"
Me.TimerInterval = 0
ElseIf Me.ckGuardProof = -1 Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
Me.LblProofGd1.ForeColor = 18432
Me.LblProofGd2.ForeColor = 18432
Me.LblProofGd2.Caption = "in file"
Me.TimerInterval = 0
myExclamation ("'Has Guardian' toggle button at right" & vbNewLine & _
"on main form Is not pressed." & vbNewLine & vbNewLine & _
"Please do so if there is Guardian.")
End If


Can anyone tell me what I'm doing wrong? I've spend days reworking code, & even trying other events....

C. Reyes
 
How are ya catrey . . .

First ... although you describe [blue]ckGuardProff[/blue] as a textbox & checkbox,I'm gonna go with [blue]checkbox[/blue] according to the content of your post origination.

Now understand ... you don't need two labels. One will do. You'll just have to [blue]size the label to two lines![/blue] In a tetxbox or label when you want to insert a newline, just hit [blue]Ctrl+Enter![/blue]. So in the [blue]ControlSource[/blue] of LblProofGd1n you'll enter:
[purple]="Proof of Guardianship[/purple] - Hit Ctrl+Enter - and enter [purple]in file?"[/purple] [purple]Type exactly what you see![/purple]
Here's where you incease the height of the label to show both lines. As a finishing touch ... center the text in the label, size the width and position the lbl proper.

Moving on to your main problem ... [purple]flashing the label![/purple]

You should be using the forms [blue]Timer[/blue] event to swap background colors. To do this you set code in the forms [blue]Timer[/blue] event to change background colors, and you set the flash rate with the [blue]Timer Interval[/blue] event Which triggers the flash!. Before we get to the events I want to show you how to pick custom color constants in access, instead of resorting to RGB.
[ol][li]Put the cursorn on any textbox (in form design view), and in the properties window put the cursor on the [blue]Back Color[/blue] property line (write down the old value to come back).[/li]
[li] Click the three elipses to the right. This should take you the [blue]Color Picker Dialog[/blue]. You select your color here, cutsto or not. When you colose out to the form you'll see the color value of the color you selected ... that all there is to it![/li]
[li]Usually you flash between a an alternate background color and the default.[/li]
[li]Now that you have yore two background constants, the [blue]On Timer[/blue] event would look like:
Code:
[blue]   Dim defBkg As Long, alt, altBkg As Long
   
   defBkg = Default Background ColorConstant
   altBKG = altbackground ColorConstant
   
   If Me!ckGuardProof = False Then
      If Me!LblProofGd1.BackColor = defBkg Then
         Me!LblProofGd1.BackColor = altBkg
      Else
         Me!LblProofGd1.BackColor = defBkg
      End If
   Else
        Me!LblProofGd1.BackColor = defBkg
        me.timerinterval=0 
   End If[/blue]
[/li][/ol]
The [blue]On Current[/blue] event would look like:
Code:
[blue]   If Me!ckGuardProof = False Then
      me!timerInterval=25
   endif[/blue]
Give it a shot and let me know of any problems!

[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1: Thank you for giving so painstaking a reply! I'm humbled.

meanwhile... there are more than several reasons I use two boxes for the two lines. First of all: Access's line break behavior (Shirt-Enter also works) usually puts the lines too far apart for my taste, so I find myself doing something like this more than I like, in general. Also: In this case, it's not the background I want to change color, but the text color. And it's the text I want to blink, not the background. Thirdly: it's only the "Proof of Guardianship" text within the label that I want to blink. So as is, the second label LblProofGd2 uses the label's margin setting to place the "in file?" text toward the bottom of a the two-line size label, and I use a transparent label LblProofGd1 placed above the "in file?" text to provide the text that will 'blink.' I did include code above that does go in the subform's On Timer event, that would set up the blinking behavior. The timer interval gets changed (to 500 to 'blink', 0 to not-blink) depending on the conditional code.

I can't figure out why the conditional code doesn't correctly produce the behavior described in the comment lines of the code I included, if I write more than one if-then set of conditions (or include any 'ElseIf' sets of conditions) that apply to what I want to happen when the controls hold each of the four possible sets of values for the two controls (the value on the subform and the value on the main form). That is respectively, -1 and -1, 1- and 0, 0 and 0, and 0 and -1. I also have to take into account null values which is the reason for the Len(Trim(Nz())) jazz when I refer to 0 values, in the code-so-far.

You are kind to go through the how-to-pick-a-color. That process is how I came to the pink, dark red and dark green color values in the code I've been trying to make work so far (though I confess I'm not familiar with what "cutsto" means).

In your proposed code are you posing that the actual number values go where you have put the text "Default Background Color Constant" and "Alt Background Color Constant"? Anywho: How to cause blinking behavior even if I wanted background color changes isn't so much my problem, as how make four particular blinking and text color change combinations contingent on each of the four possible current value combinations of TWO controls: a checkbox on the subform (which -- mea culpa! -- I DID incorrectly refer to as a textbox!) AND the toggle button TogBHasGuard on the main form. Both these types of controls store the numeric value -1 for 'yes' or 'true', and 0 for 'no' or 'false'.

So, hm. Thanks very much for your suggestions though.

C. Reyes
 
I just found that my cutting and pasting caused some extra code to show up when I put in the code that includes comment lines. It should end with:

Code:
End If

not:

Code:
End If
    If Forms!frmClientInfoEnter.TogBHasGuard = -1 And Me.ckGuardProof = -1 Then
End If

(plus the assumed End Sub and whatever error code is added)

AND yes, I did just figure out how to properly submit the code part of my posts....




C. Reyes
 
catrey . . .

The example I gave should at least give you a good idea how to flash a textbox. However the On Current event meeds to be modified a little:
Code:
[blue]   If Me!ckGuardProof = False Then
      Me!TimerInterval = 25
   Else
      Me!TimerInterval = 0
   End If[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Somehow I'm not making myself clear at all... it isn't how to flash the text that I need to know! I can get that to work fine once I have entered:

Code:
Private Sub Form_Timer()
With LblProofGd1
    .ForeColor = (IIf(.ForeColor = 14013951, 106, 14013951))
End With
End Sub

in the On Timer event of the subform, and in the AfterUpdate event of the subform ckGuardProof checkbox use one If/Then statement such as:

Private Sub ckGuardProof_AfterUpdate()
Code:
'This should cause 'Proof of Guardianship in File?' label to blink if
'main form Has-Guardian toggle is ON (yes) and subform 'Proof of
'Guardianship in File?' is NOT checked (false)
If Len(Trim(Nz(Me.ckGuardProof))) = 0 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
        Me.LblProofGd1.ForeColor = 14013951
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd2.Caption = "in file?"
        Me.TimerInterval = 500

It's when I add:

Code:
'When both subform 'Proof of Guardianship in file?' box is checked and main form 'Has
'Guardian' toggle is ON (yes), this should cause 'Proof in file?' label to turn dark
'green, remove the question mark from the label, and stop blinking behavior
    If Me.ckGuardProof = -1 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
        Me.LblProofGd1.ForeColor = 18432
        Me.LblProofGd2.ForeColor = 18432
        Me.LblProofGd2.Caption = "in file"
        Me.TimerInterval = 0
    End If
'When both subform 'Proof of Guardianship in file?' box is NOT checked and main form
''Has Guardian' toggle NOT selected (false), this should TURN OFF blinking and
'cause 'Proof in file?' font to turn dark red as well as restore question mark.
    If Len(Trim(Nz(Me.ckGuardProof))) = 0 And Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd2.Caption = "in file?"
        Me.TimerInterval = 0
    End If
'If 'Proof of Guardianship in File?' box IS checked (yes) but 'Has Guardian' toggle on main
'form is NOT checked (false), makes subform label dark green, removes checkmark, and label
'stops blinking, but launches message box prompting user to change the 'Has Guardian' toggle
'to 'yes'.
    If Me.ckGuardProof = -1 And Len(Trim(Nz(Forms!frmClientInfoEnter.TogBHasGuard))) = 0 Then
        Me.LblProofGd1.ForeColor = 18432
        Me.LblProofGd2.ForeColor = 18432
        Me.LblProofGd2.Caption = "in file"
        Me.TimerInterval = 0
        myExclamation ("'Has Guardian' toggle button at right" & vbNewLine & _
            "on main form Is not pressed." & vbNewLine & vbNewLine & _
            "Please do so if there is Guardian.")
    End If

... or any other version I've tried so far, such as the second bunch of code I added in my first post that uses ElseIf, that all of the conditional effects described in the comment lines do not happen. I can't figure out why not! Individually each of the four sets of If/Then statements seem to work when their conditions are met, if I remove the other three If/Then statements.

I do realize that if I ever come up with something that works I'll have to put something similar in the On Current event of the subform.... My thinking was, to find the code that will work in both places I could just address the After Update event here, and I could handle the rest on my own.

Thanks for trying, anyway....

C. Reyes
 
catrey . . .

Sorry for the misunderstanding. I reread and found where I went astray ... [blue]Now back on track![/blue]

There's still some confusion as to wether [blue]ckGuardProof[/blue] is a [blue]Checkbox[/blue] or [blue]Textbox?[/blue] I'm proceeding on the basis that its a checkbox.
[ol][li]Only the blinking [blue]If statement[/blue] goes in the [blue]After Update[/blue] event of [blue]ckGuardProof[/blue].
Code:
[blue]   If Me.ckGuardProof = False And Forms!frmClientInfoEnter!TogBHasGuard = True Then
      Me.LblProofGd1.ForeColor = 14013951
      Me.LblProofGd1.ForeColor = 106
      Me.lblProofGD2.Caption = "in file?"
      Me.TimerInterval = 500
   End If[/blue]
[/li]
[li]The other three [blue]IF statements[/blue] go in the [blue]On Timer[/blue] event (since they turn the timer off). Including the flash [blue]IF statement[/blue] it turns out to be:
Code:
[blue]   Dim ctlTgl As Control, ctlGuard As Control, ctlGD2 As Label
   Dim prpGD1 As Property, prpGD2 As Property
   Dim Pink As Long, DarkRed As Long, DarkGreen As Long
   
   Set ctlTgl = Forms!frmClientInfoEnter!TogBHasGuard
   Set ctlGuard = Me!ckGuardProof
   Set ctlGD2 = Me!lblProofGD2
   Set prpGD1 = Me!LblProofGd1.Properties("ForeColor")
   Set prpGD2 = Me!lblProofGD2.Properties("ForeColor")
   Pink = 14013951
   DarkGreen = 18432
   DarkRed = 106
   
   If ctlGuard = False And ctlTgl = True Then
      prpGD1 = IIf(prpGD1 = Pink, DarkRed, Pink)
   ElseIf ctlGuard = True And ctlTgl = True Then
      prpGD1 = DarkGreen
      prpGD2 = DarkGreen
      ctlGD2.Caption = "in file"
      Me.TimerInterval = 0
   ElseIf ctlGuard = False And ctlTgl = False Then
      prpGD1 = DarkRed
      prpGD2 = DarkRed
      ctlGD2 = "in file?"
      Me.TimerInterval = 0
   Else [green]'ctlGuard = True And ctlTgl = False Then[/green]
      prpGD1 = DarkGreen
      prpGD2 = DarkGreen
      ctlGD2.Caption = "in file"
      Me.TimerInterval = 0
    End If

   Set prpGD2 = Nothing
   Set prpGD1 = Nothing
   Set ctlGD2 = Nothing
   Set crlGuard = Nothing
   Set ctlTgl = Nothing[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
catrey . . .

[blue]?[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm so sorry I have not responded earlier... was out sick; and on returning have been assigned a completely unrelated report that will take some doing, and can not focus on this right now; it'll probably be a couple days at least. I _so_ appreciate your efforts but am really between a rock and Mt. Vesuvius, here! Please forgive me -- I promise I will review your response with care and let you know how it's going, as soon as I can!

Did catch at least the first graph and yes, it is a checkbox on the subform, and a toggle control on the main form.

thx and until then,

C. Reyes
 
yes, it's been forever....

I actually found, with some more experience with If-Then code and how ElseIf works and the proper order of things, that I could get it to work exactly the way I needed with just the Else/If statements properly coded.

The code goes on the Current event of the fsubGuardianship subform on the pgGuardianship tab page of my tab control on the main form (whew!) with corresponding code in the AfterUpdate event of the ckGuardProof checkbox control on the tab control subform, and the AfterUpdate event of the TogBHasGuard toggle control on the main form:

Code:
'This causes 'Proof of Guardianship in File?' label to blink if
'main form Has-Guardian toggle is ON (yes) and subform 'Proof of
'Guardianship in File?' is NOT checked (false)
If Me.ckGuardProof <> -1 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
        Me.LblProofGd1.ForeColor = 14013951
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd2.Caption = "in file?"
        Me.TimerInterval = 500
'When both subform 'Proof of Guardianship in file?' box is checked and main form 'Has
'Guardian' toggle is ON (yes), this causes 'Proof in file?' label to turn dark
'green, removes the question mark from the label, and stops blinking behavior
    ElseIf Me.ckGuardProof = -1 And Forms!frmClientInfoEnter.TogBHasGuard = -1 Then
        Me.LblProofGd1.ForeColor = 18432
        Me.LblProofGd2.ForeColor = 18432
        Me.LblProofGd2.Caption = "in file"
        Me.TimerInterval = 0
'When both subform 'Proof of Guardianship in file?' box is NOT checked and main form
''Has Guardian' toggle NOT selected (false), this TURNS OFF blinking and
'causes 'Proof in file?' font to turn dark red as well as restores the question mark.
    ElseIf Me.ckGuardProof <> -1 And Forms!frmClientInfoEnter.TogBHasGuard <> -1 Then
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd1.ForeColor = 106
        Me.LblProofGd2.Caption = "in file?"
        Me.TimerInterval = 0
'If 'Proof of Guardianship in File?' box IS checked (yes) but 'Has Guardian' toggle on main
'form is NOT checked (false), makes subform label dark green, removes checkmark, and label
'stops blinking. Also launches message box prompting user to change the 'Has Guardian' toggle
'to 'yes'
   ElseIf Me.ckGuardProof = -1 And Forms!frmClientInfoEnter.TogBHasGuard <> -1 _
    Or IsNull(Forms!frmClientInfoEnter.TogBHasGuard) Then
        Me.LblProofGd1.ForeColor = 18432
        Me.LblProofGd2.ForeColor = 18432
        Me.LblProofGd2.Caption = "in file"
        Me.TimerInterval = 0
        myExclamation ("'Has Guardian' toggle button at right" & vbNewLine & _
            "on main form Is not pressed." & vbNewLine & vbNewLine & _
            "Please do so if there is Guardian.")
    Else
'If for some ungawdly reason none of the above conditions apply, launches
'message box to advise programmer for the time being (I will probably remove
'this message box code eventually - the SF after Guardianship Status lets me
'know it's code on the subform that's the problem)
        myInfMssg "Unexpected status of 'Proof of Guardianship" & Chr(13) _
            & "in file' on subform and 'Has Guardian' button" & Chr(13) _
            & "on main form.", "Guardianship Status – SF"
    End If

Thank you for all your assistance! Your insights are always valuable and appreciated.


C. Reyes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top