473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Open up a MDI form

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
CheckUser()
If ID > 0 Then
GetEmployeeInformation(ID)
fMain.Member_ID = ID
fMain.Member_FirstName = fName
fMain.Member_LastName = lName
fMain.Member_Permission = permission
Try
fMain.Show()
Catch ex As Exception
MsgBox(ex.Message)
End Try

Me.Hide()
Else
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.OLED B.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)
Try
cnn.Open()
ID = tmpCmd.ExecuteScalar
Catch ex As Exception
Finally
cnn.Close()
End Try
End If
End Function

Private Sub GetEmployeeInformation(ByVal intID As Integer)
Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.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() _
{(myDataSet.Tables("employees").Columns("id"))}
Dim drw1 As DataRow = myDataSet.Tables("employees").Rows.Find(CInt(intID ))
Try
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
Jan 12 '08 #1
1 1546
dip_developer
648 Expert 512MB
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
CheckUser()
If ID > 0 Then
GetEmployeeInformation(ID)
fMain.Member_ID = ID
fMain.Member_FirstName = fName
fMain.Member_LastName = lName
fMain.Member_Permission = permission
Try
fMain.Show()
Catch ex As Exception
MsgBox(ex.Message)
End Try

Me.Hide()
Else
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.OLED B.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)
Try
cnn.Open()
ID = tmpCmd.ExecuteScalar
Catch ex As Exception
Finally
cnn.Close()
End Try
End If
End Function

Private Sub GetEmployeeInformation(ByVal intID As Integer)
Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.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() _
{(myDataSet.Tables("employees").Columns("id"))}
Dim drw1 As DataRow = myDataSet.Tables("employees").Rows.Find(CInt(intID ))
Try
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
why are you calling the MDI form in frmLogin_Load?????....you should call it after a user logs in ...i.e after checking the user credentials.....call it in cmdLogin_Click............
moreover when you are calling MDI write the code like...
Expand|Select|Wrap|Line Numbers
  1.  fMain = New frmMain 
  2. fMain.Show()
  3.  
Jan 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs...
2
by: Julia Baresch | last post by:
Hi everyone, As some of you may know, we've been having trouble with an unrecognized database format error. Today I installed an unfinished project on the workstation of one of my users. ...
1
by: petersk | last post by:
Firstly I am an older person trying to teach myself to create a project and teach myself Access VBA programming along the way. I anticipate a number of problems I will need help with but here...
14
by: Simon Abolnar | last post by:
I would like to know how to open child form from dialog form. Thanks for help! Simon
3
by: rdemyan via AccessMonster.com | last post by:
My application is split into a front end and back end. Each user has their own copy of the front end. There are a few forms I only want to be open for one user at a time. So I've implemented the...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
6
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
10
waynetheengineer
by: waynetheengineer | last post by:
Hi, I'm trying to write code for a form when it closes. It's supposed to requery a combo box depending on which form is currenlty open in the background behind the current form, shown below: ...
19
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.