By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

conditionally changing backcolor of textbox

P: 23
I have a form with four textboxes: A, B, C and D. Textbox A contains a date value. Textbox B is entered by the user, at which point the program locates a value in a table and uses that value to populate textbox C. Textbox D simply displays the difference between textbox A and C. After textbox C is populated and textbox D is calculated, I want the program to see if textbox D is larger than 5, if so I want it to change the background color to red.

D is currently set to Back color -2147483633 and Backstyle Normal.

I tried the following code to accomplish this:

[code]
Private Sub D_Change()
If D.Value > 5 Then
D.BackColor = vbRed
End Sub
[code]



but this has not done anything. I think there's something I'm not understanding about when _change() runs. Any help would be appreciated. Thanks.
Nov 16 '07 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
The Think the Change event only fires if the textbox is physically changed, i.e. the user presses a key that enters data, not if the textbox is filled programatically. You need to place your code to change the box color in your code, immediately after the calculation is done. Exactly where does that occur?

Or, if you're running ACC2000 or later you could use Conditional Formatting.

Linq ;0)>
Nov 16 '07 #2

P: 23
That was what I was thinking about _change(). The calculation for textbox D is done directly in the text box itself. The data control source property for textbox D is :

=[A]-[C]

I did the conditional formatting and it worked perfectly. Didn't even realize that was available. Thanks for the simple fix.
Nov 16 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Nov 16 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.