Conditional formatting on Form

DeanRowe

Registered User.
Local time
Today, 19:56
Joined
Jan 26, 2007
Messages
142
Hi,

I have five text boxes on my form where I enter my data, its very important that a button is pressed after anything is entered into any of the text boxes.

I want to have a “bulb” (or realistically an empty text box) underneath these five boxes that starts off being “lit” green – but whenever any of the five text boxes has its data changed I want it to turn red. Then, when the important button is pressed the box turns green again.

I have tried researching conditional formatting but it’s a little above my head and I’m really struggling with this one. Would anyone please mind helping me with the code? The text fields are labelled A1, A2, A3, A4 & A5 and the button is “Button1”.

I have 10 sets of text fields and buttons in all (B1, C1, Button2, Button3 etc) so I’m hoping to replicate the code for the other sets. I also have a “master button” with its own “bulb” that needs to be pressed after all the “bulbs” are green – I’m hoping that after I’ve got the hang of the above I can use the same principles on this “master button”.

Thank you very much for your time, any help, advice or pointers to any good tutorials would be welcomed greatly.

Thanks again

Dean
 
Your explanation is not entirely clear as to what you're trying to accomplish, but from what I can tell, it sounds like you're really over-engineering this thing, with the "bulbs" changing color, then changing color again after a button is pressed! When you have a piece of code that simply has to be executed after data is entered into a textbox, the standard approach is to place the code in the AfterUpdate event for the textbox. You avoid all the changing of bulb colors back and forth, and the code will be run without relying on the user. If a piece of code has to be run after a number of textboxes have been filled in, you could use the AfterUpdate event of the form itself, again without user intervention.

If textboxes have data entered, run one piece of code:
Code:
Private Sub TextBox1_AfterUpdate()
  If Not IsNull(Me.TextBox1) Then
    MsgBox "Code from button is run here"
  End If
End Sub

Private Sub TextBox2_AfterUpdate()
If Not IsNull(Me.TextBox2) Then
    MsgBox "Code from button is run here"
  End If
End Sub

Private Sub TextBox3_AfterUpdate()
If Not IsNull(Me.TextBox3) Then
    MsgBox "Code from button is run here"
  End If
End Sub

If you need other code to be run if all three boxes are filled in:
Code:
Private Sub Form_AfterUpdate()
If Not IsNull(Me.TextBox1) And Not IsNull(Me.TextBox2) And Not IsNull(Me.TextBox3) Then
  MsgBox "Master button code goes here!"
End If
End Sub

In reality, of course, you would replace the message boxes with your actual code!


Linq
 
Last edited:

Users who are viewing this thread

Back
Top Bottom