3 Replies - 2601 Views - Last Post: 16 November 2012 - 07:09 AM Rate Topic: -----

#1 bluevirus24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-November 12

Compile Error: End If Without Block If

Posted 15 November 2012 - 09:11 PM

I need some problems here in my code that supposedly a Log-In and Log-out of Students,Faculty,Visitors

Can you find out what is lacking.. I'm having a hard time debugging.. Please..

Private Sub cmdlogin_Click()
Set connection1 = New ADODB.Connection
Set connection2 = New ADODB.Connection

ctr = 1
currentdate = DateValue(Now)
currenttime = TimeValue(Now)

If txtlogin = "" Then
MsgBox "Please Enter ID Number", vbCritical, "Information"
End If

If ctr = 1 Then
connection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb;Persist Security Info=False"
connection1.Open

rs.Open "Select * from STUDENTS, connection1"
    If txtlogin = rs!IDNum Then
    MsgBox "Record Found! Log-in Anyway?", vbYesNo, "Information"
        
        If answer = vbYes Then
        Set rs = New Recordset
        connection2.connectionstrinf = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb;Persist Security Info=False"
        connection2.Open
        
        rs.Open "Select * from LOGHISTORY", connection2
        rs.AddnNew
            rs!IDNum = txtlogin
            rs!LoginDate = currentdate
            rs!LoginTime = currenttime
            MsgBox "Log-In Successful", vbInformation, "Information"
                Else
                MsgBox "ID Number Not Found", vbInformation, "Information"
                End If
            End If
        End If
End If
End Sub

This post has been edited by AdamSpeight2008: 15 November 2012 - 09:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Compile Error: End If Without Block If

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Compile Error: End If Without Block If

Posted 15 November 2012 - 09:21 PM

Error message is very self explanatory.

Compile Error: End If Without Block If

You have an End If that doesn't have a corresponding If ... Then.

It be easier to find if you indent your code.
Sub Example 
  Rem Indented 
  If somecondition Then
    Rem Indented
     Some code
     If someOtherCondition Then
       Rem Indented
     Else
       Rem Indented
     End If
  Else
    Rem Indented
  End If
End Sub


So you can see what level each line of code is at.

This post has been edited by AdamSpeight2008: 15 November 2012 - 09:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: Compile Error: End If Without Block If

Posted 16 November 2012 - 02:52 AM

As Adam has said, just count your IF statements and count your ENDIF statements.
Was This Post Helpful? 0
  • +
  • -

#4 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Compile Error: End If Without Block If

Posted 16 November 2012 - 07:09 AM

the last end if you have in the code is not needed, remove it and the problem is solved
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1