1

Topic: Change of color of a field at data input

Hello! As I can not understand that I do not so. Visual check of entered values is necessary to me. When the operator enters the data, given are processed and, depending on result color of a cell changes.
For an example made the form and wrote such code:

Private Sub p2_AfterUpdate ()
qBC
End Sub
Private Sub qBC ()
On Error Resume Next
Dim q As String
q = ""
q = Nz (Val (Me! p2) - Val (Me! p0), No)
Select Case q
Case No
Me! p2.BackColor = vbWhite
Case Is> 0 <= 150
Me! p2.BackColor = vbGreen
Case Is <0
Me! p2.BackColor = vbRed
Case Is> 150
Me! p2.BackColor = vbYellow
End Select
Debug. Print q
End Sub

But the code does not work how I planned. It is possible to tell, it at all does not work.
At once in a makeweight a question, whether it is possible to make so that color of a field changed at value input in the field, instead of after field update, as at me now. Tried to write the same code to event change, but it caused an error.

2

Re: Change of color of a field at data input

Valery Zimin;
Check fulfill not on After and on BeforeUpdate (before field update)

Private Sub p2_BeforeUpdate (Cancel As Integer)
If Not condition Then ' operators =, <<, <>, and, or
The message
Cancel = True ' the cursor does not quit a field the correct data will not be entered yet
End If

End Sub

3

Re: Change of color of a field at data input

sdku;
Thanks for the answer. It is necessary for me, that check was not rigid but that the operator saw if there are any deviations and itself made the decision, to import or not to import the data. Therefore the problem is not solved. I attach a form example in which the similar logic as does not work.

4

Re: Change of color of a field at data input

Zimin wrote:

sdku;
Thanks for the answer. It is necessary for me, that check was not rigid but that the operator saw if there are any deviations and itself made the decision, to import or not to import the data. Therefore the problem is not solved. I attach a form example in which the similar logic as does not work.

1. Change of color of a field - changes color of all column.
2.  this rainbow is necessary?  not .
3. The distinct text of the warning in the field nearby - is much more useful.

5

Re: Change of color of a field at data input

aleks222;
1) Is any other method to define color of object?
2)...
3) I like a situation described also a question on it, instead of asked another's judgement how better to signal.

6

Re: Change of color of a field at data input

Conditional formatting.

7

Re: Change of color of a field at data input

Valery Zimin, at you the code incorrect - string variable try to compare to numbers.

Private Sub p2_AfterUpdate ()
qBC
End Sub
Private Sub qBC ()
On Error Resume Next
Dim q As Integer
q = 0
q = Nz (Val (Me! p2) - Val (Me! p0), 0)
Select Case q
Case 0
Me! p2.BackColor = vbWhite
Case Is> 0 <= 150
Me! p2.BackColor = vbGreen
Case Is <0
Me! p2.BackColor = vbRed
Case Is> 150
Me! p2.BackColor = vbYellow
End Select
Debug. Print q
End Sub

8

Re: Change of color of a field at data input

;
+To 100500 you in a karma!)))
Very much helped.
But))) it began to be played, added a calculation output in Immidiate window to see, result and again the same glitch:
If Case it is set by an interval (> 0 <100, for example) handling goes only on a condition> 0. That is, if I ask to select a cell green, and calculation 100 or more, a cell all the same the green.
Plus ceased to be processed Null.
I do not understand is a glitch or I "Mr. a tree"?
Handling in real time - once again thanks!

9

Re: Change of color of a field at data input

Valery Zimin;

Private Sub p2_Change ()
If Not IsNull (Me.p0) Then
Select Case Me.p2.Text - Me.p0
Case Is <0
Me.p2.BackColor = vbRed
Case 0 To 100
Me.p2.BackColor = vbGreen
Case 100.001 To 200
Me.p2.BackColor = vbYellow
End Select
Else
Me.p2.BackColor = vbWhite
End If
End Sub

10

Re: Change of color of a field at data input

All thanks for the help. With the job of intervals with the help <or> (for example:> = 0 <30) and did not understand (access perceives only the first part of a condition (> =0). Plus, for correct operation is required to specify variable type (Long, Integer, etc.).

11

Re: Change of color of a field at data input

sdku wrote:

Select Case Me.p2.Text - Me.p0
Case Is <0
Me.p2.BackColor = vbRed
Case 0 To 100
Me.p2.BackColor = vbGreen
>>> Case 100.001 To 200 <<<
Me.p2.BackColor = vbYellow
End Select

Generally for this purpose exists Case Else. And that will be entered by the user 10,0005 - and all to nothing.

12

Re: Change of color of a field at data input

Zimin wrote:

With the job of intervals with the help <or> (for example:> = 0 <30) and did not understand (access perceives only the first part of a condition (> =0)

Case Is> = 0 AND Is <30

13

Re: Change of color of a field at data input

Akina wrote:

Case Is> = 0 AND Is <30

No, such constructions VBA does not perceive, alas

14

Re: Change of color of a field at data input

Instead of Cfse it is possible to try to use and structure If... ElseIf... But there the subtleties. There is a serial check of all conditions.

15

Re: Change of color of a field at data input

MrShin wrote:

such constructions VBA does not perceive, alas

Yes, , in VBA conditions unite a comma which is interpreted as OR.
There is a sense to use that check of conditions is fulfilled sequentially, and one of restrictions to check up an alternative condition above under the text. I.e. type

Case Is <0 ' the first is checked immediately
Case Is <30 ' with the registration of the first it is equivalent Is> = 0 AND Is <30
Case Is <100 ' with the registration of the previous it is equivalent Is> = 30 AND Is <100
Case Else ' with the registration of the previous it is equivalent Is> = 100
Joss wrote:

there the subtleties. There is a serial check of all conditions.

The same as and in case of Case. Distinction only that ElseIf allows to fulfill check different expressions, type

If x <0 Then ' the first is checked immediately
ElseIf y <0 Then ' with the registration of the first it is equivalent x> = 0 AND y <0
Else ' with the registration of the previous it is equivalent x> = 0 AND y> = 0

16

Re: Change of color of a field at data input

Akina wrote:

Yes, , in VBA conditions unite a comma which is interpreted as OR.

It is possible to use case true