Solved Update the value of a field based on two other fields (1 Viewer)

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
Hi
I am new to the forum and also to learning Access

I want while typing in a field called

result

If the value that I write is less than the value in the field named

low

Or greater than the value in the field named

High

Two things happen:

1 - Color of the value in a field

RESULT

It change in to red color

The field background change in to yellow

The second thing is a field -called

state

It takes the value

L

If it is a value of

RESULT

less than

low



------------------------

and It takes the value

H

If more than

high

Exactly like the picture
 

Attachments

  • high  or low.gif
    high or low.gif
    142.2 KB · Views: 31
  • high or low.accdb
    928 KB · Views: 46
Last edited:

bob fitz

AWF VIP
Local time
Today, 08:44
Joined
May 23, 2011
Messages
4,726
Suggest that you take a look at "Conditional formatting" of your control on the form
 

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
Suggest that you take a look at "Conditional formatting" of your control on the form
I want these changes to occur while writing and not when leaving the field, exactly as in the picture
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:44
Joined
May 21, 2018
Messages
8,529
Code:
Private Sub Result_Change()
  Dim rslt As Double
  If IsNumeric(Me.Result.Text) Then
    rslt = Me.Result.Text
    If rslt < Me.low Then
      Me.State = "L"
    ElseIf rslt > Me.high Then
      Me.State = "H"
    Else
      Me.State = Null
    End If
  Else
    Me.State = Null
    MsgBox "Result must be numeric", vbInformation
  End If

End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:44
Joined
May 21, 2018
Messages
8,529
When you type into a textbox the Value of the textbox is not updated until the textbox after update event. That does not occur until you leave the textbox. So prior to leaving the textbox the Text property and Value property are not the same. Therefore you have to use the Text property if you want to check immediately after typing.
 

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
Else
Me.State = Null
MsgBox "Result must be numeric", vbInformation

I NEED THIS textbox ACCEPT TEXT AND NUMBERS
 

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
When you type into a textbox the Value of the textbox is not updated until the textbox after update event. That does not occur until you leave the textbox. So prior to leaving the textbox the Text property and Value property are not the same. Therefore you have to use the Text property if you want to check immediately after typing.
If I delete the value that I wrote in the text box, I want to change the status value to NULL
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:44
Joined
May 21, 2018
Messages
8,529
ACCEPT TEXT AND NUMBERS
How are letters between two numbers? Makes no sense.
How do you plan to determine if a letter is between two values? Can you give an example?
is "Dog" supposed to be between 70 and 110?

You can use Val if the numbers come first, but not if they come after the letters
?val("123A")
123
?val("abc123")
0

Maybe this
Code:
Private Sub Result_Change()
  Dim rslt As Double
  If (Me.Result.Text & "") <> "" Then
    rslt = Val(Me.Result.Text)
    If rslt < Me.low Then
      Me.State = "L"
    ElseIf rslt > Me.high Then
      Me.State = "H"
    Else
      Me.State = Null
    End If
  Else
    Me.State = Null
  End If
End Sub

If I delete the value that I wrote in the text box, I want to change the status value to NULL
The original code already did that.
 

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
How are letters between two numbers? Makes no sense.
for example result of HCV Ab ( Positive 0.98 ) i need when i write positive, condition of field applied but when i write Negative 0.18 do no change for textbox
 

Safaa

New member
Local time
Today, 10:44
Joined
Jan 3, 2024
Messages
7
in the Conditional formatting i put this control

[state] Like "*L*" Or [state] Like "*H*" Or [state] Like "*low*" Or [state] Like "*High*" Or [Result] Like "*Equi*" Or [Result] Like "*Pos*" Or [Result] Like "*+*" Or [Result] Like "*>*" Or [Result] Like "*<*" Or [Result] Like "*Few*"
 

Users who are viewing this thread

Top Bottom