how to call another form

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 17
Reputation: tirso is an unknown quantity at this point 
Solved Threads: 0
tirso tirso is offline Offline
Newbie Poster

how to call another form

 
0
  #1
Jun 15th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how to call another form

 
0
  #2
Jun 15th, 2008
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()
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: how to call another form

 
1
  #3
Jun 15th, 2008
To call form2 you must to make an object of form2 :
  1. Dim MainMenu as New Form2
  2. 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 :
  1. Dim MainMenu as New Form2
  2. MainMenu.show
  3. Me.Dispose(False)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 17
Reputation: tirso is an unknown quantity at this point 
Solved Threads: 0
tirso tirso is offline Offline
Newbie Poster

Re: how to call another form

 
0
  #4
Jun 19th, 2008
Originally Posted by tuse View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 17
Reputation: tirso is an unknown quantity at this point 
Solved Threads: 0
tirso tirso is offline Offline
Newbie Poster

Re: how to call another form

 
0
  #5
Jun 19th, 2008
thank you so much to all of your replied. It's worked. Until next post
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 1
Reputation: Nrew123 is an unknown quantity at this point 
Solved Threads: 0
Nrew123 Nrew123 is offline Offline
Newbie Poster

Re: how to call another form

 
0
  #6
Aug 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 271
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 55
GeekByChoiCe GeekByChoiCe is offline Offline
Posting Whiz in Training

Re: how to call another form

 
0
  #7
Aug 15th, 2009
in my oppinion the easiest way would be to create an overloaded New and call it with parameter (byval caller as From)
example:
  1. Public Sub New(ByVal caller As Form)
  2. InitializeComponent()
  3. Select Case caller.Name
  4. Case "Form2"
  5.  
  6. Case "Form1"
  7.  
  8. Case Else
  9.  
  10. End Select
  11. End Sub

and call the new form like Dim formtest As New Form1(Me)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 9333 | Replies: 6
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC