Change textbox background colour pending value of two textboxes on a form (1 Viewer)

andersar

New member
Local time
Today, 20:15
Joined
Jul 10, 2013
Messages
3
I have a form with two textboxes that get their values from two different queries that counts records from table. If textbox1.value equals texbox2.value the textbox2.value back ground colour is green. If they are not equal textbox2.value goes red. Itried with using conditional formatting, but it doesn't work all the time as the form is not updating when it is opened. Any suggestions on how tosolve this?
 

Mihail

Registered User.
Local time
Today, 13:15
Joined
Jan 22, 2011
Messages
2,373
Code:
Private Sub SetBackColor()
   If textbox1.Value=textbox2.Value then
     textbox2.BackColor = Green 'Replace Green with the number or vb constant for color if exist vbGreen
   Else
     textbox2.BackColor = Red 'Replace Red with the number or vb constant for color if exist vbGreenRed
   End If
End Sub
Apply this procedure from the appropriate event like
OnCurrent for the form or AfterUpdate for the textboxes or OnChange for the textboxes etc.
 

andersar

New member
Local time
Today, 20:15
Joined
Jul 10, 2013
Messages
3
Code:
Private Sub SetBackColor()
   If textbox1.Value=textbox2.Value then
     textbox2.BackColor = Green 'Replace Green with the number or vb constant for color if exist vbGreen
   Else
     textbox2.BackColor = Red 'Replace Red with the number or vb constant for color if exist vbGreenRed
   End If
End Sub
Apply this procedure from the appropriate event like
OnCurrent for the form or AfterUpdate for the textboxes or OnChange for the textboxes etc.

Thank you Very much for the response. I have one problem though. If I open the form by double clicking the form it works not a problem, but if I install a button to open this form on my Main Form, it seems the colours does not update properly like the colours are applied before the query updates the numbers. Any suggestion what this is caused.
 

Mihail

Registered User.
Local time
Today, 13:15
Joined
Jan 22, 2011
Messages
2,373
Try
Me.Repaint
after you change the colors.
I think that will work but if this is statement have a high frequency, will be bad for the user eyes.
 

Users who are viewing this thread

Top Bottom