Multiple IF ElseIF statements not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • formsrtuff
    New Member
    • Apr 2010
    • 3

    #1

    Multiple IF ElseIF statements not working

    Hello all,

    I'm trying to get multiple IF, THEN statements to work. Based on several examples, I believe it is coded properly, however, when I execute the code, nothing happens with the exception of one condtion.

    Here's the code and condition:

    Code:
        If Exterior.Value = "Snow Hauling" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
            Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Snow Hauling] Like '" & Nz(Yes) & "*'"
            Me.FilterOn = True
            
        ElseIf Exterior.Value = "Complete Lawn Care" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
                Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Complete Lawn Care] Like '" & Nz(Yes) & "*'"
                Me.FilterOn = True
        End If
    The only time it works, is when state = ND, zip = 58102 and the exterior value = complete lawn care. When I put in other combinations that should produce results, nothing happens.

    Any help is appreciated.
    Last edited by Stewart Ross; Apr 14 '10, 09:00 PM. Reason: Please use the [Code] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    That seems weird. Have you tried other non-blank values for [StateCmbo] & [ZipCmbo] with [Exterior] still "Complete Lawn Care"?
    Is [Exterior] a ComboBox or ListBox control (Operator freehand is not advised to match up with existing names)?

    Comment

    • formsrtuff
      New Member
      • Apr 2010
      • 3

      #3
      Exterior is a combobox. i actually shortened the code:
      Code:
      If Exterior.Value = "Snow Hauling" And Me.statecmbo = "PA" Then
        Me.Filter = [Vendor State] = Me.statecmbo
      Else
        DoCmd.OpenForm "switchboard", acNormal
      End If
      When I execute the search, nothing happens, not even the Else statement. So now, I'm really confused.

      Any insight is appreciated.
      Last edited by NeoPa; Apr 15 '10, 02:24 PM. Reason: Please use the [CODE] tags provided.

      Comment

      • formsrtuff
        New Member
        • Apr 2010
        • 3

        #4
        Just stumbled on something. When all the fields are Null, and I click on the search button, the switchboard opens. Strange.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Reducing posted code can be a good idea when you know you are removing stuff which is not relevant to the problem. In this case that doesn't appear to be the case. Your second set of code bears little or no resemblance to the first, so instead of clarifying the situation it merely makes trying to work out what you're about so much harder.

          As your latest code has a line that cannot possibly compile even, it seems to me that a good place to start would be for me to dig up some basic starting point ideas that will help you put down a question we can start to work on.
          When posting any code on here please :
          1. Ensure you have Option Explicit set (See Require Variable Declaration).
          2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
          3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
          4. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.

          If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.

          Comment

          Working...