Greater and Less Then

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

This code doesn't seem to work. It's in Red. I think the syntax is
wrong. Any help appreciated.
Thanks
DS

If Forms!frmOrderScreen!TxtPrepSelected >=3 AND <=6 Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If
 
In
DS said:
This code doesn't seem to work. It's in Red. I think the syntax is
wrong. Any help appreciated.
Thanks
DS

If Forms!frmOrderScreen!TxtPrepSelected >=3 AND <=6 Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If

You have to repeat the subject of the comparison:

If Forms!frmOrderScreen!TxtPrepSelected >=3 _
And Forms!frmOrderScreen!TxtPrepSelected <=6 _
Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If

Or, to be a bit more concise:

With Forms!frmOrderScreen!TxtPrepSelected
If .Value >=3 And .Value <=6 Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If
End With

Either form will work -- the second should be marginally more efficient,
because Access doesn't have to chase down the object reference twice.
 
DS said:
This code doesn't seem to work. It's in Red. I think the syntax is
wrong. Any help appreciated.
Thanks
DS

If Forms!frmOrderScreen!TxtPrepSelected >=3 AND <=6 Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If

This line:

If Forms!frmOrderScreen!TxtPrepSelected >=3 AND <=6 Then

should read:

If Forms!frmOrderScreen!TxtPrepSelected >=3 AND
Forms!frmOrderScreen!TxtPrepSelected <=6 Then

or even better:

Dim ctl As Access.Textbox
Set ctl = Forms!frmOrderScreen!TxtPrepSelected
If ctl.Value >= 3 And ctl.Value <= 6 Then
 
Dirk said:
In


You have to repeat the subject of the comparison:

If Forms!frmOrderScreen!TxtPrepSelected >=3 _
And Forms!frmOrderScreen!TxtPrepSelected <=6 _
Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If

Or, to be a bit more concise:

With Forms!frmOrderScreen!TxtPrepSelected
If .Value >=3 And .Value <=6 Then
MsgBox "Temp"
Else
MsgBox "No Temp"
End If
End With

Either form will work -- the second should be marginally more efficient,
because Access doesn't have to chase down the object reference twice.
Thanks
Works great.
DS
 
Back
Top