Results 1 to 4 of 4
  1. #1
    Holli is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    46

    End if without block if error or Else without If error

    I am trying to make it required that an Employee select their employee ID number with the following code that I just added in red. I keep getting a End if without Block If error. Cant see what I am doing wrong. Thanks for any help.

    If Len(Me.EMP_ID & vbNullString) = 0 Then MsgBox "You must select your Employee ID"
    Cancel = True
    Me.EMP_ID.SetFocus
    End If


    Else

    RunCommand acCmdSaveRecord
    If MsgBox("Would you like to print your report?", vbYesNo) = vbYes Then
    DoCmd.OpenReport "NAVAL ARCHITECTURE EMPLOYEE REPORT", acViewNormal, , "EmployeeID=" & Me.EmployeeID
    Else
    End If
    If MsgBox("Would you like to continue?", vbQuestion + vbYesNo) = vbYes Then
    Me.Requery
    DoCmd.Close
    Else
    DoCmd.CloseDatabase
    End If
    End Sub


    Holli

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Use indentation and structure is easier to read and debug. Maybe this is what you want.
    Code:
    If Len(Me.EMP_ID & vbNullString) = 0 Then
        MsgBox "You must select your Employee ID"
        Cancel = True
        Me.EMP_ID.SetFocus
    Else
        If MsgBox("Would you like to print your report?", vbYesNo) = vbYes Then
            RunCommand acCmdSaveRecord
            DoCmd.OpenReport "NAVAL ARCHITECTURE EMPLOYEE REPORT", acViewNormal, , "EmployeeID=" & Me.EmployeeID, acDialog
        End If
        If MsgBox("Would you like to continue?", vbQuestion + vbYesNo) = vbYes Then
            Me.Requery
            DoCmd.Close
        Else
            DoCmd.CloseDatabase
        End If
     End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Anything after "THEN" should be on a new line.
    The first "Else" is in the wrong place. Should be between IF and END IF.

    There are two forms of "IF..End IF ".
    One is a single line...... example:
    Code:
    If Len(Me.EMP_ID & vbNullString) = 0 Then MsgBox "You must select your Employee ID"
    I never use this form....

    The other is the block form
    If MsgBox("Would you like to continue?", vbQuestion + vbYesNo) = vbYes Then
    Code:
      Me.Requery
      DoCmd.Close
    Else
      DoCmd.CloseDatabase
    End If
    Not sure what you program flow should be. Tell us what should happen and when.

  4. #4
    Holli is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    46
    Perfect Thank you !!!

    Holli

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  2. Complie error "End If without Block If
    By justair07 in forum Access
    Replies: 8
    Last Post: 12-13-2013, 09:03 AM
  3. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums