user3596788
user3596788

Reputation: 95

If statement with textbox color as a condition

This is for Access 2007 using VB on a form. I'm trying to run some code when all 3 text boxes are green and if they aren't green a message box will appear asking to correct errors before exporting. Is there a better way to to evaluate 3 conditions? And to read the color value should I use Me.Text1.Value = vbgreen?

I appreciate your help

 If Me.Text1 = "vbgreen" And Me.Text3 = "vbgreen" and Me.Text5 = "vbgreen" Then
    Call RunExpZip
    Else
    msg = MsgBox("Please correct errors before exporting", vbCritical)
    End If

Upvotes: 0

Views: 1398

Answers (1)

Andy G
Andy G

Reputation: 19367

Unless the text in the textboxes is actually the word "vbgreen" then you need to check the BackColor property of the textboxes. (Or ForeColor if it is the text-colour, rather than the background.)

This value won't evaluate to vbGreen (65280) though; standard green will have the value 5026082:

If Me.Text1.BackColor = 5026082 Then
    'etc.

Presumably, though, the colour is set using Conditional Formatting. In which case it would be better (in my opinion) to check the conditions (that would make them green) rather than checking the colour itself. (A tiny change to the colour would mean the if-condition(s) will not be met.)

Upvotes: 2

Related Questions