UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Change Form Or Label Back Color Based On Label Value, Access 2010    
 
   
pbkcrafts
post Feb 16 2017, 10:56 AM
Post#1



Posts: 2
Joined: 1-February 17



No expert here, I have the attached for that I am trying to modify:

My goal is to have the form back round or if it is simpler just a label that is GREEN until the label (TIMER VALUE) value reaches 30 min and then turns RED
Thank you

code:

Private lngNumOfSecs As Long
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

DoCmd.Quit

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub

Private Sub Command2_Click()
Me.TimerInterval = 0
Me![lblTime].Caption = "00:00:00"
lngNumOfSecs = 0
End Sub

Private Sub Command3_Click()
Me.TimerInterval = 0
End Sub

Private Sub Command4_Click()
Me.TimerInterval = 100 'removed one zero
End Sub

'my code
Private Sub Form_Dirty(Cancel As Integer)
If Me!lngNumOfMins >= ("00:00:50") Then
Me.Label8.BackColor = vbRed
Else
Me.Label8.BackColor = vbBlue
End If
End Sub





Private Sub Form_Timer()
Dim lngNumOfHrs As Long
Dim lngNumOfMins As Long
Dim lngNumOfSecsRem As Long

lngNumOfSecs = lngNumOfSecs + 1

Select Case lngNumOfSecs
Case Is > 86400 '>1 day - not equipped for that
Case Is >= 3600 '>1 hour
lngNumOfHrs = lngNumOfSecs \ 3600
lngNumOfMins = ((lngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
Case Is >= 60 '>1 minute
lngNumOfMins = ((lngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
Case Is > 0 '< 1 minute
lngNumOfSecsRem = lngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
Case Else 'shouldn't happen, but who knows?
End Select

Me![lblTime].Caption = Format$(lngNumOfHrs, "00") & ":" & Format$(lngNumOfMins, "00") & _
":" & Format$(lngNumOfSecsRem, "00")



End Sub
This post has been edited by pbkcrafts: Feb 16 2017, 11:05 AM
Attached File(s)
Attached File  PC1.jpg ( 29.24K )Number of downloads: 0
 
Go to the top of the page
 
GroverParkGeorge
post Feb 16 2017, 11:32 AM
Post#2


UA Admin
Posts: 28,630
Joined: 20-June 02
From: Newcastle, WA


Welcome to UtterAccess.

You can add a line of code to do either.

This changes the back color of the form's detail section.

Me.Detail.BackColor = vbRed

Me.lblYourFlagLabel.BackColor = vbRed

To change them back to the original color, use the equivalent code line and the appropriate color constant: vbBlack, vbGreen, etc. If you want to use some color other than the basics for which there are defined constants, you can create your own, or just use the color definition.
This post has been edited by GroverParkGeorge: Feb 16 2017, 11:33 AM

--------------------
Go to the top of the page
 
pbkcrafts
post Feb 16 2017, 11:47 AM
Post#3



Posts: 2
Joined: 1-February 17



Thank you for the reply George,

Rather green here


so what your suggesting is something like:

if Me![lblTime].Caption >("00:30:00") then

(this-the above- is the part I am stuck at, my target "time value on the label " I don't think I am referencing it correctly)


me. [somenewlbl] BackColor = vbRed

Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    20th February 2017 - 04:02 AM