If statement results inconsistent

M

Marissa

I have a userform where the user enters some numbers. I want to check that
the number identified as "mininum temp" is lower than the one identified as
"maximum temp". I wrote:

Private Sub CommandButton2_Click()
'next button
ActiveDocument.FormFields("mintemp").Result = mintemp.Value
ActiveDocument.FormFields("maxtemp").Result = maxtemp.Value
ActiveDocument.FormFields("cur").Result = cur.Value
ActiveDocument.FormFields("minpres").Result = minpres.Value
ActiveDocument.FormFields("avgh").Result = avgh.Value
ActiveDocument.FormFields("maxh").Result = maxh.Value
ActiveDocument.FormFields("process").Result = process.Value
ActiveDocument.FormFields("contam").Result = contam.Value

If mintemp.Value = "" Then
MsgBox ("Please enter minimum temperature.")
mintemp.SetFocus

ElseIf maxtemp.Value = "" Then
MsgBox ("Please enter maximum temperature.")
maxtemp.SetFocus

ElseIf cur.Value = "" Then
MsgBox ("Please enter current temperature")
cur.SetFocus

ElseIf avgh.Value = "" Then
MsgBox ("Please enter average humidity.")
avgh.SetFocus

ElseIf maxh.Value = "" Then
MsgBox ("Please enter maximum humidity.")
maxh.SetFocus

ElseIf mintemp.Value > maxtemp.Value Then
MsgBox ("Minimum temperature cannot be greater than
maximum temperature.")
mintemp.SetFocus

Else
ambient.Hide
AirTreatDetail.Show
End If
End Sub

This works the first time, and maybe the second time, but the more times I
go through it the less it works. Sometimes I can only avoid the message box
when both numbers are equal.

What is wrong?
 
P

Perry

Hi Marissa,
You have to change the validation:

Instead of using:
If bla Then
ElseIf blabla Then
Elseif blablabla Then
End if

Use:
If bla Then
'Some action
End if

If blabla Then
'Some other validation action
End if
....etc

Try to find out why

Krgrds,
Perry
 

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

Top