Open Up An MDI Form

  • 13 years ago
    I have an application that I am building. I have a normal windows form as a login. If the users are accepted, it opens up a MDI parent form as the frmMain. However, when I try to open the form, I am getting an error : Object Reference not set to an instance of an object.

    Below is the code for the frmLogin that calls the frmMain. If i start my project to start wtih the frmMain instead of the frmLogin, it opens right up with no problem. When I switch it back to start with the frmLogin, I receive the error. Here is my code:

    Public Class frmLogin
    Inherits System.Windows.Forms.Form
    'Path for Database
    Public strPath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\snma.mdb"
    Dim fMain As frmMain

    Dim dapEmployee As OleDb.OleDbDataAdapter
    Dim myDataSet As New DataSet
    Dim ID As Integer
    Dim fName As String
    Dim lName As String
    Dim instructor As Integer
    Friend WithEvents SkinEngine1 As Sunisoft.IrisSkin.SkinEngine
    Dim permission As String

    Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    If ID > 0 Then
    fMain.Member_ID = ID
    fMain.Member_FirstName = fName
    fMain.Member_LastName = lName
    fMain.Member_Permission = permission
    Catch ex As Exception
    End Try

    MsgBox("Invalid Username and Password")
    End If
    End Sub

    Private Function CheckUser() As Integer
    Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath)
    ID = 0
    If txtUsername.Text <> "" And txtPassword.Text <> "" Then
    Dim tmpCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT ID FROM Employees WHERE Username='" & txtUsername.Text & "' AND Password='" & txtPassword.Text & "'", cnn)
    ID = tmpCmd.ExecuteScalar
    Catch ex As Exception
    End Try
    End If
    End Function

    Private Sub GetEmployeeInformation(ByVal intID As Integer)
    Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath)
    Dim sql As String = "SELECT * FROM Employees WHERE id=" & intID
    dapEmployee = New OleDb.OleDbDataAdapter(sql, cnn)
    dapEmployee.Fill(myDataSet, "employees")
    myDataSet.Tables("employees").PrimaryKey = _
    New DataColumn() _
    Dim drw1 As DataRow = myDataSet.Tables("employees").Rows.Find(CInt(intID))
    If Not (drw1 Is Nothing) Then
    If Not drw1.IsNull(0) Then ID = drw1.Item(0)
    If Not drw1.IsNull(1) Then fName = drw1.Item(1)
    If Not drw1.IsNull(2) Then lName = drw1.Item(2)
    If Not drw1.IsNull(5) Then permission = drw1.Item(5)
    End If
    Catch ex As Exception
    End Try
    End Sub

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    fMain = New frmMain
    End Sub
    End Class

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup