Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Compile Error: Block IF without END IF

    I am fairly new to VB. My code keeps breaking and displaying this message:

    Compile Error: Block IF without END IF

    I think I have found that this is a bug in VB6 and I don't know how to fix my code so it will run.

    Any help out there?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    14,914
    Can you post the smallest sample of code that you can create that demonstrates the problem?

    -PatP

  3. #3
    Join Date
    Apr 2004
    Location
    LA, CA
    Posts
    125
    Without looking at your code and as the error code indicates, you are missing an End IF. make sure that for every IF statement that includes more that one instruction you have an End IF.

    eg:
    'here you need End IF
    If a = b then
    instruction 1
    intruction 2
    end if

    'this is fine too. you don't need end if here.
    if a= b then instruction

    Hope this helps. As Pat said, a sample of your code would help diagnose the problem.

  4. #4
    Join Date
    Sep 2004
    Posts
    1
    I have the exact opposite of this problem. My form says, "End If without Block If", and it has completely confused me because I do not have an extra End If.

  5. #5
    Join Date
    Feb 2005
    Posts
    1
    What you have to do is change ur if statements
    for example
    if text1.text = "lol" then
    end
    elseif text1.text = "it works" then
    text1.text = "hoorah"
    pretty simple to fix

  6. #6
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    another thing to quickly check is to make sure you dont have anything like this

    if test then
    with something
    end if
    end with

    or any loops built such etc.

    Change them to open and close sequentially i.e.

    if test
    with something
    end with
    end if

  7. #7
    Join Date
    Jan 2010
    Location
    Fiji
    Posts
    4
    Please help, I am really new to vb I got a compile error saying "Block If Without End If"
    and everytime I try correcting it, it still gives me the same error and End Sub is highlighted...I am working with Option buttons which I am new to. Here's the code:

    If optRateA.Value = True Then
    intGross = intHours * optRateA
    Else
    If optRateB.Value = True Then
    intGross = intHours * optRateB
    Else: optRateC.Value = True
    intGross = intHours * optRateC
    End If

    Please help me!

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    14,914
    Code:
    If optRateA.Value = True Then
      intGross = intHours * optRateA
    Else
      If optRateB.Value = True Then
        intGross = intHours * optRateB
      Else: optRateC.Value = True
        intGross = intHours * optRateC
      End If
    Does this help? Code formatting can be a wonderful thing!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  9. #9
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Quote Originally Posted by Pat Phelan View Post
    Code:
    If optRateA.Value = True Then
      intGross = intHours * optRateA
    Else
      If optRateB.Value = True Then
        intGross = intHours * optRateB
      Else: optRateC.Value = True
        intGross = intHours * optRateC
      End If
    Does this help? Code formatting can be a wonderful thing!

    -PatP
    Indeed.


    In visual studio, hold down Ctrl, then press "K", then WITHOUT LETTING GO OF CTRL, press "D".

    Tends to cut down on time needed to hunt down issues with control structure formatting...


    Also, look in to using a RadioButtonList. You could condense that to a single line by hitting up the SelectedValue/SelectedIndex properties:

    intGross = intHours * yourRadioButtonList.SelectedValue
    Last edited by Teddy; 01-29-10 at 15:54.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  10. #10
    Join Date
    Jan 2010
    Location
    Fiji
    Posts
    4
    I am also doing a database for a company using vb6 and I'm just a beginner...I've already connected the database but then I have to make reports which I have already done but then I have to make a report which shows stocks that are less than 100...are there any codes to make reports show that without creating them?

    help please!

  11. #11
    Join Date
    Jan 2010
    Location
    Fiji
    Posts
    4
    Thanx alot for the help!!!

  12. #12
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    14,914
    Do you have an answer for your reporting question?

    If so, you're welcome. If not, I'll split this out as a separate message thread.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  13. #13
    Join Date
    Jan 2010
    Location
    Fiji
    Posts
    4
    well actually I didnt use any code but I just created the data report..drag and drop the controls onto the report..but I just don't really know how to make a report show stocks that are less than 100.
    well this is what I did, I went back to Access where the data came from and I made another column, naming it Stocks <100 and putting a checkbox next to every item and checking those items that have less than 100....or is there another way to do this????

  14. #14
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Depends on how your database is layed out.

    How did you decide which stocks should get a checkbox?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  15. #15
    Join Date
    Aug 2011
    Posts
    3

    you need an additional End If

    Quote Originally Posted by CathyMe View Post
    Please help, I am really new to vb I got a compile error saying "Block If Without End If"
    and everytime I try correcting it, it still gives me the same error and End Sub is highlighted...I am working with Option buttons which I am new to. Here's the code:

    If optRateA.Value = True Then
    intGross = intHours * optRateA
    Else
    If optRateB.Value = True Then
    intGross = intHours * optRateB
    Else: optRateC.Value = True
    intGross = intHours * optRateC
    End If

    Please help me!

    this is an older post so maybe you have already figured it out but you have two IF statements - so you need two End IF statements - logically the nested IF statemtent is part of the same process so you ay have been thinking you are doing End If on the whole block - but the code requires an End If to match each one.

    I am trying to solve my own compile error - but have about 5 nested IF statements - It looks like I have enough end ifs - unless I am looiking in the wrong place - keep in mind that you only need an End If after a block IF in other words a single like such as:

    if true = true then msgbox ("True")

    does NOT need an End If

    whereas

    if true = true then
    msgbox ("True")
    truth = true
    End If

    DOES need an End If

    thing that annoys me on my issue is that I coudl have sworn I solved it earlier today and saved it - but it came back - so somewhere along the way I did not get some of my work earlier today saved.

Posting Permissions

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