Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Location
    Staffs, England
    Posts
    18

    Unanswered: Combo box oddness

    I am trying to Write a vba if statement that tests if the combobox has anything in it or not and the if statement doesn't seem to find a NULL value or a blank one.
    I can't figure out why.

    heres the code:
    If cmbFormcodeGrouping = Null Then
    strFormcodeSQL = "SELECT * FROM products Where manufacturer = """ & Me!cmbFormcodeManufacturer _
    & """ AND prod_group = """ & cmbFormcodeProdGroup & """ AND inactive = FALSE AND grouping = '" _
    & "' Order By " & Me!cmbFormcodeOrder
    strFormcodeOutfile = "c:\formcode.txt"
    Else
    strFormcodeSQL = "SELECT * FROM products Where manufacturer = """ & Me!cmbFormcodeManufacturer _
    & """ AND prod_group = """ & cmbFormcodeProdGroup & """ AND inactive = FALSE AND grouping = '" _
    & cmbFormcodeGrouping & "' Order By " & Me!cmbFormcodeOrder

    End If



    Where cmbFormcodeGrouping is my combobox.

    Please help!!
    Cheers,
    Dion

  2. #2
    Join Date
    Feb 2003
    Location
    Wichita,KS
    Posts
    44
    Change your If statement format to:
    If IsNull(cmbFormcodeGrouping) Then

    Here is what Microsoft says about checking for Null.
    IsNull Function
    Returns a Boolean value that indicates whether an expression contains no valid data (Null).
    Syntax

    IsNull(expression)

    The required expression argument is a Variant containing a numeric expression or string expression.

    Remarks
    IsNull returns True if expression is Null; otherwise, IsNull returns False. If expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression.

    The Null value indicates that the Variant contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It is also not the same as a zero-length string (""), which is sometimes referred to as a null string.

    Important Use the IsNull function to determine whether an expression contains a Null value. Expressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var <> Null, are always False. This is because any expression containing a Null is itself Null and, therefore, False.

  3. #3
    Join Date
    Feb 2003
    Location
    Staffs, England
    Posts
    18

    cheers

    I knew it was some syntax I'd mucked up.
    cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •