BackColor problem

brsawvel

Registered User.
Local time
Today, 08:59
Joined
Sep 19, 2007
Messages
256
Hello, I attempted to write a code to change the background color of a textbox when data is entered -

The color starts at yellow and I want it to change to white when someone enters data. The code I used was:

Code:
Private Sub Form_Open (Cancel As Integer)
 
If fldOverallClassification.Value Is Not Null Then fldOverallClassification.BackColor = vbWhite
End If
 
End Sub

I get a "End If: If not defined" error that points to the "Private Sub" line. What am I doing wrong? Also, I'm sure the Form_Open is not a good place for this code. Where can I place this code so that the textbox automatically changes on edit and goes back to yellow if no data is entered or data is deleted?
 
The Open event of a form is too early in the process to reference any controls on the form. Use the OnLoad event instead. You are also going to want to look up the IsNull() function in the VBA Help system.
 
You are also going to want to look up the IsNull() function in the VBA Help system.

What exactly am I looking for in the VBA Help System?

A little more detail --> the error message is "Compile Error: End If without Block If". I'm not sure why this error is coming up if I have an If statement before End If.
 
I tried developing a new code:

Code:
 If Me![OverallClassification].value = "" Then Me![OverallClassification].BackColor = vbWhite
Else: Me![OverallClassification].BackColor = vbYellow
End IF

I got an "Else without If" error. It doesn't see my If statement at the beginning?
 
Try:
Code:
If Len(Me.OverallClassification & "") > 0 Then
   Me.OverallClassification.BackColor = vbWhite
Else
   Me.OverallClassification.BackColor = vbYellow
End If
 
usage

if x then dothis

OR

if x then
do this
else
do something else
end if


but not

if x then dothis
else: do something else
end if

in this latter case the line
if x then dothis is a complete statement

so you THEN have a "floating" else, and a endif - hence the error
 
Hey RuralGuy:

Awesome! You are King.

Just one more question. Is there a On??? where it makes the change as soon as data is entered?
 
Of Course I figured it out as soon as I asked. sorry (It's the AfterUpdate for the textbox..right?)
 
Of Course I figured it out as soon as I asked. sorry (It's the AfterUpdate for the textbox..right?)
 

Users who are viewing this thread

Back
Top Bottom