954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to call another form

Hi to all

I have two forms, one is form1 for registration and the other one is form2 for my main menu. How to call the form2 if the user successfully register with the form1. The code in form 1 is me.close (to close the form1) then form2.show but it will not work.

Thanks in advance

Tirso

tirso
Newbie Poster
22 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

let us say you have a login button on the registration form which gets enabled on validation of registration details.

code for login button- form2.showdialog()

in the form_load for the 2nd form, do form1.hide()

and in the form closing event for the 2nd form, remember to do form1.close()

tuse
Junior Poster
173 posts since Jul 2007
Reputation Points: 32
Solved Threads: 14
 

To call form2 you must to make an object of form2 :

Dim MainMenu as New Form2
MainMenu.show


To close form1 after called form2 :
- Don't use Me.Close cause it will close application.
- Use Dispose(), set it to false.
e.g :

Dim MainMenu as New Form2
MainMenu.show
Me.Dispose(False)
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

let us say you have a login button on the registration form which gets enabled on validation of registration details.

code for login button- form2.showdialog()

in the form_load for the 2nd form, do form1.hide()

and in the form closing event for the 2nd form, remember to do form1.close()

thank you so much. It's worked

tirso
Newbie Poster
22 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

thank you so much to all of your replied. It's worked. Until next post

tirso
Newbie Poster
22 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

Hi guys, can you help me in my vb.net project. The problem is that I need to call a form, but I also need to know the form who calls the next form. Because I plan to make an if statement so that the program will know which line of code to execute depending on the form who calls the next form.

It's a database program. And I already have this line of code for the savings account alone. I will need more line of codes for the Dollar and current accounts.

This line of code will read the database. It's a log-in form that accesses the database:

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents and Settings\Student\nrew\db1.mdb;")
Dim cmd As OleDbCommand = New OleDbCommand("Select * from clients where NAME= '" & TextBox1.Text & "' AND PIN = '" & TextBox2.Text & "' ", cn)


cn.Open()

Dim rdr As OleDbDataReader
rdr = cmd.ExecuteReader

If rdr.HasRows Then
rdr.Read()
NoAcc = rdr("NAME")
NoPin = rdr("PIN")
If (TextBox1.Text = NoAcc And TextBox2.Text = NoPin) Then NoAccmod2 = NoAcc
wdb.Show()
Me.Hide()

Else
MsgBox("Incorrect AccountName or PIN", MsgBoxStyle.Critical, "Sorry try again")
TextBox1.Clear()
TextBox2.Clear()

End If


Please help, the only thing I need is to have a reference on what form calls the next form.

Nrew123
Newbie Poster
1 post since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

in my oppinion the easiest way would be to create an overloaded New and call it with parameter (byval caller as From)
example:

Public Sub New(ByVal caller As Form)
        InitializeComponent()
        Select Case caller.Name
            Case "Form2"

            Case "Form1"

            Case Else

        End Select
    End Sub


and call the new form like Dim formtest As New Form1(Me)

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

I wanna check if AboutBox2 called AboutBox5, if any other form/aboutbox called it, that and that should happen. How to do that?

Aangiix3
Newbie Poster
20 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You