473,409 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Else without If error on compile

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 18734
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
make that four "End If" statements. Seems like you are assuming the VB "IF...ELSE...END 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
Nope, putting those in doesn't help, it breaks at the 'else' on line 38. Hmmmmm.
Feb 22 '08 #4
did you put in four "End If" statements?
Feb 22 '08 #5
add 3 more "End If" statements at line 35...
Feb 22 '08 #6
NeoPa
32,556 Expert Mod 16PB
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 Expert Mod 2GB
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
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
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
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...
8
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...
0
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...
35
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
5
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...
3
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...
56
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...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.