Function String Extras Class

StringsToSQLBetweenExpression

Convert two values into a SQL WHERE expression that will locate a range of values. The exact form of the expression depends upon which of vFrom and vThru are provided.

Signature (Visual Basic / VBA)

Public Function StringsToSQLBetweenExpression( _
      Optional ByVal vFrom As Variant _
    , Optional ByVal vThru As Variant _
    ) As String

Code Example

    StringsToSQLBetweenExpression("A", "B") = "Between ""A"" And ""B"""
    StringsToSQLBetweenExpression(Null, "B") = "<= ""B"""
    StringsToSQLBetweenExpression("A", Null) = ">= ""A"""
    StringsToSQLBetweenExpression(Null, Null) = "Is Null"
    StringsToSQLBetweenExpression(12) = ">= ""12""" ' #5

Parameters

Parameter Description
vFrom String value representing the lower bound of the range of values to be located with the SQL WHERE expression. vFrom defaults to Null (which means that it is does not exist, i.e. there is no lower bound) if it is missing or Null or cannot be fixed up to a String.
vThru String value representing the upper bound of the range of values to be located with the SQL WHERE expression. vThru defaults to Null (which means that it is does not exist, i.e. there is no upper bound) if it is missing or Null or cannot be fixed up to a String.

Notes & Version History

Note This function only works with vFrom and vThru values that are strings. If either of these arguments if numeric, they will be fixed up to a String as in example #5.
Note Embedded double quote characters within either vFrom or vThru will be prefixed by an additional double-quote character so that Microsoft's SQL will not interpret them as the double-quote which ends the string literal.