473,563 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Else without If error on compile

24 New Member
Hi - Was wondering if anybody could tell me why this rather crappy code is giving me an 'Else without If' error on compile?
All the Elses and Ifs look ok to me but there's a few.

Expand|Select|Wrap|Line Numbers
  1. Private Sub MySearchButtonClick()
  2. If gcfHandleErrors Then On Error GoTo PROC_ERR
  3.   PushCallStack "MySearchButton"
  4.  
  5. If Me.AllowFlexibility = True Then
  6.         If Me.UseSpecialism = True And Me.UseCountryExperience = True Then
  7.             If Me.Active = True Then
  8.                 DoCmd.OpenQuery "Qry_amin5WithBothactive"
  9.             Else
  10.                 DoCmd.OpenQuery "Qry_amin5WithBoth"
  11.             End If
  12.         Else
  13.         If Me.UseSpecialism = True And Me.UseCountryExperience = False Then
  14.             If Me.Active = True Then
  15.                 DoCmd.OpenQuery "Qry_amin5WithSpecialismsactive"
  16.             Else
  17.                 DoCmd.OpenQuery "Qry_amin5WithSpecialisms"
  18.             End If
  19.         Else
  20.         If Me.UseSpecialism = False And Me.UseCountryExperience = True Then
  21.             If Me.Active = True Then
  22.                 DoCmd.OpenQuery "Qry_amin5WithCountryExpactive"
  23.             Else
  24.                 DoCmd.OpenQuery "Qry_amin5WithCountryExp"
  25.             End If
  26.         Else
  27.         If Me.UseSpecialism = False And Me.UseCountryExperience = False Then
  28.             If Me.Active = True Then
  29.                 DoCmd.OpenQuery "Qry_amin5JoinEliminateSearchactive"
  30.             Else
  31.                 DoCmd.OpenQuery "Qry_amin5JoinEliminateSearch"
  32.             End If
  33.  
  34.         End If
  35.  
  36. Else
  37.  
  38. If Me.UseSpecialism = True And Me.UseCountryExperience = True Then
  39.             If Me.Active = True Then
  40.                 DoCmd.OpenQuery "Qry_WithBothactive"
  41.             Else
  42.                 DoCmd.OpenQuery "Qry_WithBoth"
  43.             End If
  44.         Else
  45.         If Me.UseSpecialism = True And Me.UseCountryExperience = False Then
  46.             If Me.Active = True Then
  47.                 DoCmd.OpenQuery "Qry_WithSpecialismsactive"
  48.             Else
  49.                 DoCmd.OpenQuery "Qry_WithSpecialisms"
  50.             End If
  51.         Else
  52.         If Me.UseSpecialism = False And Me.UseCountryExperience = True Then
  53.             If Me.Active = True Then
  54.                 DoCmd.OpenQuery "Qry_WithCountryExpactive"
  55.             Else
  56.                 DoCmd.OpenQuery "Qry_WithCountryExp"
  57.             End If
  58.         Else
  59.         If Me.UseSpecialism = False And Me.UseCountryExperience = False Then
  60.             If Me.Active = True Then
  61.                 DoCmd.OpenQuery "Qry_JoinEliminateSearchactive"
  62.             Else
  63.                 DoCmd.OpenQuery "Qry_JoinEliminateSearch"
  64.             End If
  65.         End If
  66.  
  67.  
  68. PROC_EXIT:
  69.   PopCallStack
  70.   Exit Sub
  71.  
  72. PROC_ERR:
  73.   GlobalErrHandler
  74.   Resume PROC_EXIT
  75. End Sub
Feb 22 '08 #1
8 18751
maxvernon
12 New Member
without knowing exactly what the intention of the code is the compiler is telling you to add 3 "End If' statements just above line 68. for example:

67 End If
68 End if
69 End If
70 Proc_Exit ' This line used to be line 68


should do the trick
Feb 22 '08 #2
maxvernon
12 New Member
make that four "End If" statements. Seems like you are assuming the VB "IF...ELSE...EN D IF" statement works like the Java "IF ELSE" statement which doesn't have an "END IF". In VB you must end each IF statement with a matching END IF
Feb 22 '08 #3
pelicanstuff
24 New Member
Nope, putting those in doesn't help, it breaks at the 'else' on line 38. Hmmmmm.
Feb 22 '08 #4
maxvernon
12 New Member
did you put in four "End If" statements?
Feb 22 '08 #5
maxvernon
12 New Member
add 3 more "End If" statements at line 35...
Feb 22 '08 #6
NeoPa
32,564 Recognized Expert Moderator MVP
A good starting place would be to indent your code to match the If & looping structures. You have indenting of sorts, but as it doesn't match the code it's going to work against rather than for you.
Lines 2 & 3 need to be rewritten. Your intentions are unclear here so I can't suggest replacement code.
The rest will be obvious to you with correct indentation of the code. You're not simply interested in adding three "End If"s. You must add them into the logically correct positions. Only you can determine where that is for your logic.
Feb 24 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
NeoPa's right. With correct indentation and logic design things will fall into place.

As NeoPa pointed out it is not just about adding Endifs. For interest I have removed all the inner if-then's which call one routine when 'active' is true and another when not. Straight away the unended if-then-elses become apparent, as do the flaws in the logic. There are unnecessary tests of True and False occurrences of the same variable in consecutive statements (lines 2 & 4 below, 6 & 8, etc).

As an aside, I think you meant to use Elseif instead of the consecutive Else and If statements, but this would not help the flawed logic.

Getting the logic right from the start would give you a better chance at a working solution - adding Endifs to keep the compiler happy is no solution to poor structure and logic.

Expand|Select|Wrap|Line Numbers
  1.  
  2. If Me.AllowFlexibility = True Then
  3.         If Me.UseSpecialism = True And Me.UseCountryExperience = True Then
  4.         Else
  5.         If Me.UseSpecialism = True And Me.UseCountryExperience = False Then
  6.         Else
  7.         If Me.UseSpecialism = False And Me.UseCountryExperience = True Then
  8.         Else
  9.         If Me.UseSpecialism = False And Me.UseCountryExperience = False Then
  10.         End If
  11. Else
  12. If Me.UseSpecialism = True And Me.UseCountryExperience = True Then
  13.         Else
  14.         If Me.UseSpecialism = True And Me.UseCountryExperience = False Then
  15.         Else
  16.         If Me.UseSpecialism = False And Me.UseCountryExperience = True Then
  17.         Else
  18.         If Me.UseSpecialism = False And Me.UseCountryExperience = False Then
  19.         End If
  20.  
-Stewart
Feb 24 '08 #8
pelicanstuff
24 New Member
Many thanks. I think I need to read some books quite urgently.

Don't worry about lines 2 and 3, they are for error handling. gcfHandleErrors is a global variable that determines whether debug mode is on or off.

It looks like I did mean to use Elseif - I've managed to muddle along so far (learning as I go along), but clearly I need to do some proper research.

Food for thought.
Feb 29 '08 #9

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

Similar topics

2
1767
by: pentiumPunk | last post by:
for some reason i thought i could have more if statements than else statements. if (!inputFile) { cerr<<"file not found"; } if (something) {
5
3496
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to be really clever and use : #if subsearch ... #else ..... #end if
8
5416
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and do not compile with "Allow Unsafe Code Blocks=false" set to true, then the project compiles and no problems. BUT if I compile with "Allow Unsafe...
0
2392
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at...
35
2139
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
5
4739
by: sam_cit | last post by:
Hi Everyone, I read somewhere that there are some compile time operations behind switch-case, which is why it can work for cases which evaluates to an integer or character and not strings and that it makes switch-case faster than if-else statements, is it true and if so what is the underlying concept behind a switch-case compilation? Can...
3
3159
by: Naha | last post by:
The if else statement inside my jsp is not working, it gives me the following error: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
56
5689
by: valentin tihomirov | last post by:
{ int i = 2; } int i = 1; There is no 'i' defined in the 'parent' context from the moment of declaration on. So what is the problem? They tell us they pursue language simplicity. The rule "do not define a variable more than once in the same context" is natural, and simplest therefore. All normal languages obey it therefore....
1
3848
by: Alex | last post by:
Hi This might seem an unusual request! Does anybody know how to rebuild an ASP.NET 1.1 application on server without Visual studio (i.e. compile on the server itself). It would be fine if it was an ASP.NET 2.0 application I guess (would recompile on the fly).
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.