If Statement

  • Thread starter Thread starter Trini Gal
  • Start date Start date
T

Trini Gal

Hello,

I have the following code and it works fine:

Private Sub L_READING_AfterUpdate()

Dim DISTANCE As Integer
DISTANCE = 10

If L_DISTANCE = DISTANCE Then
READING = L_READING
ElseIf L_DISTANCE < DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
ElseIf L_DISTANCE > DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
Else
MsgBox "DISTANCE IS BLANK, PLEASE REVISE."
End If

End Sub

I want to tweek it a little to say:

If reading > 1300 then "Cannot be greater than 1300, please revise."

I tried adding another ElseIf, but its not working. Any help is greatly
appreciated.

Thanks in advance for your time.
 
You need it as first test.
It never will work as last test due testing < Distance and > Distance
already as it will always be one of these.
 
Trini said:
Hello,

I have the following code and it works fine:

Private Sub L_READING_AfterUpdate()

Dim DISTANCE As Integer
DISTANCE = 10

If L_DISTANCE = DISTANCE Then
READING = L_READING
ElseIf L_DISTANCE < DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
ElseIf L_DISTANCE > DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
Else
MsgBox "DISTANCE IS BLANK, PLEASE REVISE."
End If

End Sub

I want to tweek it a little to say:

If reading > 1300 then "Cannot be greater than 1300, please revise."

I tried adding another ElseIf, but its not working. Any help is
greatly appreciated.

Thanks in advance for your time.

A case statement usually makes things easier to read.

Select Case L_DISTANCE

Case DISTANCE ' = 10
READING = L_READING
Case "" 'it's blank
MsgBox "DISTANCE IS BLANK, PLEASE REVISE."
Case > 1300
MsgBox "Cannot be greater than 1300, please revise."
Case Else
READING = ((L_DISTANCE / DISTANCE) * L_READING)
End Select
 
Karl and Mike,

Thank you so much for your quick responses, but after I posted I figured it
out. My code now looks like this:

Private Sub L_READING_AfterUpdate()

Dim DISTANCE As Integer
Dim CANCEL As Integer
DISTANCE = 10

If L_DISTANCE = DISTANCE Then
READING = L_READING
ElseIf L_DISTANCE < DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
ElseIf L_DISTANCE > DISTANCE Then
READING = ((L_DISTANCE / DISTANCE) * L_READING)
End If
If READING > 1300 Then
CANCEL = True
MsgBox "THE READING (uV/m)CANNOT BE GREATER THAN 1,300 PLEASE REVISE."
L_READING.SetFocus
End If

End Sub

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Returning back to Original value 2
Acsess 2007 -2010 0
Simplify code 3
Code optimisation 5
Can't get off record from AfterUpdate 1
IF Function for Football stats 1
If Statements 2
textbox - combobox 2

Back
Top