0

People pls help me i am getting a compiler error - Loop Without Do
This is my Code

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Shyam\Documents\Database1.mdb;Persist Security Info=False"
cn.Open()
rs = New ADODB.Recordset
rs.Open("select* from STUDENTSWITHHOA", cn, adOpenKeyset, adLockOptimistic)

Do Until rs.EOF

    If rs!RegNo = Text2.Text Then
        If IsNull(rs("Name")) Then
            answer = MsgBox("The Register Number You Entered Didnt Provide All The Inforamtion Do you still Want to Display the Details", vbYesNo + vbExclamation, "Alert")
            If answer = vbYes Then
                Text1.Text = rs!Name
                Text3.Text = rs!MobileNo
                Text4.Text = rs!E_mailId
                Text5.Text = rs!ArrearYear
                Text6.Text = rs!ArrearSemester
                Text7.Text = rs!ArrearSubject
                Text8.Text = rs!HOA
                If answer = vbNo Then
                    Form1.Show()
                Else
                    rs.MoveNext()
                End If
Loop
MsgBox("THE REGISTER NUMBER U ENTERED DOES NOT HAVE HISTORY OF ARREARS")
rs.Close

Edited by Reverend Jim: fixed formatting

3
Contributors
2
Replies
52
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0

look at your code with a bit of formatting.

Do Until rs.EOF

    If rs!RegNo = Text2.Text Then
        If IsNull(rs("Name")) Then
            answer = MsgBox("The Register Number You Entered Didnt Provide All The Inforamtion Do you still Want to Display the Details", vbYesNo + vbExclamation, "Alert")
            If answer = vbYes Then
                Text1.Text = rs!Name
                Text3.Text = rs!MobileNo
                Text4.Text = rs!E_mailId
                Text5.Text = rs!ArrearYear
                Text6.Text = rs!ArrearSemester
                Text7.Text = rs!ArrearSubject
                Text8.Text = rs!HOA
                    If answer = vbNo Then
                        Form1.Show
                    Else
                        rs.MoveNext
                    End If

This Loop statement is isolated withing an if-then block without a Do Statement to pair with

                Loop


                MsgBox "THE REGISTER NUMBER U ENTERED DOES NOT HAVE HISTORY OF ARREARS"
                rs.Close

You can not isolate parts of statement pairs in another paired statement block like If-End IF.

1

I reformatted your code. Notice how you are missing a few End If statements. Close your if blocks and you should be fine.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.