Between function in VBA

  • Thread starter Thread starter MN
  • Start date Start date
M

MN

Hi,
How can we convert this code become a BETWEEN function:
(Rs_Cum1.Fields("Site").Value >= 18 And Rs_Cum1.Fields("site").Value <= 24)

Thanks you,
NM
 
There is no BETWEEN function in VBA as there is in FoxPro. Use to use it a
lot when I did FoxPro.
You could write one yourself. You would have to user Variant data types for
the arguments so it could be used with any type of data.
 
Thanks for your info.
Regards

Klatuu said:
There is no BETWEEN function in VBA as there is in FoxPro. Use to use it a
lot when I did FoxPro.
You could write one yourself. You would have to user Variant data types for
the arguments so it could be used with any type of data.
 
This is a simple version that I use for some things.

Public Function IsBetween(ByVal TestValue As Variant, _
ByVal LowerLimit As Variant, _
ByVal UpperLimit As Variant) As Boolean

If UpperLimit < LowerLimit Then
Call Swap(LowerLimit, UpperLimit)
End if

If TestValue < LowerLimit Then
IsBetween = False
ElseIf TestValue > UpperLimit Then
IsBetween = False
Else
IsBetween = True
End If

End Function

Public Sub Swap(ByRef FirstValue As Variant, _
ByRef SecondValue As Variant)

Dim varTempValue As Variant

varTempValue = FirstValue
FirstValue = SecondValue
SecondValue = varTempValue

End Sub

HTH
Dale
 
Back
Top