By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Multiple IF ElseIF statements not working

P: 3
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:

Expand|Select|Wrap|Line Numbers
  1.     If Exterior.Value = "Snow Hauling" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
  2.         Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Snow Hauling] Like '" & Nz(Yes) & "*'"
  3.         Me.FilterOn = True
  5.     ElseIf Exterior.Value = "Complete Lawn Care" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
  6.             Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Complete Lawn Care] Like '" & Nz(Yes) & "*'"
  7.             Me.FilterOn = True
  8.     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.
Apr 14 '10 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 31,494
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)?
Apr 15 '10 #2

P: 3
Exterior is a combobox. i actually shortened the code:
Expand|Select|Wrap|Line Numbers
  1. If Exterior.Value = "Snow Hauling" And Me.statecmbo = "PA" Then
  2.   Me.Filter = [Vendor State] = Me.statecmbo
  3. Else
  4.   DoCmd.OpenForm "switchboard", acNormal
  5. End If
When I execute the search, nothing happens, not even the Else statement. So now, I'm really confused.

Any insight is appreciated.
Apr 15 '10 #3

P: 3
Just stumbled on something. When all the fields are Null, and I click on the search button, the switchboard opens. Strange.
Apr 15 '10 #4

Expert Mod 15k+
P: 31,494
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.
Apr 15 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.