Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

me.close closes whole app, not the form

Status
Not open for further replies.

696796

Programmer
Aug 3, 2004
218
GB
Public Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click



Dim sql = "SELECT UserID, fullname, userLevel FROM tblUser WHERE LoginName='" & txtUserName.Text & "' AND LoginPassword='" & txtPassword.Text & "'"

Dim conn As OleDbConnection = carDba.getCn
Dim cmd As OleDbCommand
Dim dsUser As New DataSet



cmd = New OleDbCommand(sql, conn)
conn.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader

Try
If dr.Read = False Then
MessageBox.Show("Authentication failed, please ensure that the username and password you entered are correct...", MessageBoxButtons.RetryCancel)
conn.Close()
Exit Sub
Else

'puts userId and full name into global variables
dbaCAR.UserId = dr.GetValue(0)
dbaCAR.strFullName = dr.GetString(1)
dbaCAR.intUserLevel = dr.GetValue(2)

Dim main As New mdiCAR
With main
.WindowState = FormWindowState.Maximized
.ControlBox = True
.Show()

End With

End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

conn.Close()


End Sub
 
If the form is the startup object of the application, then closing it will cause the primary thread to end.

If you want to close the first form, you should change the startup object to be a module that launches the form. You can run into the same issue though, as soon as the start up method completes, the application will end.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
In mine rather than close I set the first form .visible = False after opening the second and it works fine. The form is still there it just cannot be effected by the user.

-I hate Microsoft!
-Forever and always forward.
 
i had the idea of starting my mdiform as the startup object, then on load of that having the login screen appear - the problem is that on_load event keeps firing so the login keeps appearing.

What is the best way around this problem? all i want is to open the form, go through the login, anfd then open my main menu inside my mdiForm. Any ideas and help is much apreciated,

Al
 
In the mdiForm's constructor (sub new), show the login form modally. If the login fails, toss an error and shut down the app. If the login succeds, let the mdiForm's constructor continue.

And Chrissie, You say public shared class, I say module, half dozen one way, 6 the other ;)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
this works!

Dim mdiCar As mdiCAR = New mdiCAR
mdiCar.WindowState = FormWindowState.Maximized

Me.Hide()
mdiCar.ShowDialog()
 
Hello,

Dim mdiCar As mdiCAR = New mdiCAR
mdiCar.WindowState = FormWindowState.Maximized

Me.Hide()
mdiCar.Show()
Me.dispose(false)


This is a much better way, because you can actually get rid of the splash form. In your previous way it was hidden and did not release the used resources.
That's what I use.

?
 
I run my splash a bit different. In the constructor of the primary form I launch the splash screen and pass it the primary form and a time frame. The splash screen runs in its own thread so that the main form and data load are not effected. It watches the main form object to determine when it's load is complete. Once the main form's load is done and the specified time has passed, the main form opens and the splash screen fades out.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top