0

I have a form load sub routine here and the problem is that the program executes the first one (namely, LoadProgrammes()) and then skips the rest of the subroutine. There is something about the subroutine LoadProgrammes() that makes the rest of "Form Load" not get called.

The same goes for ListActiveClasses(). Only DisplayGroups() is called properly and the next line of code is called.

I literally have no idea why and it is extremely difficult to find a google solution. Thanks in advance to whomever can help.

Private Sub frmEnroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    LoadProgrammes()
    ListActiveClasses()
    DisplayGroups()

End Sub

Private Sub LoadProgrammes()
    Dim strLoadSQL As String
    Dim dsLoad As New DataSet
    Dim daLoad As OleDb.OleDbDataAdapter

    Using con As New OleDbConnection(My.Settings.ConnectionPath)

        strLoadSQL = "SELECT Programme FROM Programmes"
        daLoad = New OleDb.OleDbDataAdapter(strLoadSQL, con)
        daLoad.Fill(dsLoad, "LoadProgrammes")

        'Add items to the combobox
        For i = 0 To dsLoad.Tables("LoadProgrammes").Rows.Count
            cmbProgramme.Items.Add(dsLoad.Tables("LoadProgrammes").Rows(i).Item(0))
        Next

    End Using
End Sub
Faizal
  • 783
  • 1
  • 6
  • 23
Pejman Poh
  • 493
  • 2
  • 8
  • 20

1 Answers1

2

What I have seen, is that in some event handlers (maybe like your Form.Load handler), any exception that is thrown during execution will simply be swallowed, and ignored. Most likely you are getting some exception in your OleDb code, that is causing it to bail out.

I would recommend wrapping all of your _Load subroutine with a Try...Catch block, and manually printing out the exception, or calling Debugger.Break.

Have you tried stepping through the code? I would recommend that you set a breakpoint at the beginning of frmEnroll_Load, and start stepping through until something blows up, or the code just continues (which is what you would see if the exception was getting swallowed.)


Related questions / pages:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Yeah you were right, it was an error. However I spent a whole day trying to debug my code and it never occurred to me that the form.load handler would just ignore errors because that doesn't, and still doesn't make any sense to me. I put breakpoints on every line of code but it simply never ran the lines and that put in an array of confusion. – Pejman Poh Jul 26 '12 at 05:05
  • I've added some links I'm sure you'll find interesting. Also edited to sound less mean in the third paragraph :-) – Jonathon Reinhart Jul 26 '12 at 05:08