943,748 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 31637
  • VB.NET RSS
Jun 15th, 2008
-1

how to call another form

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tirso is offline Offline
22 posts
since Jun 2008
Jun 15th, 2008
0

Re: how to call another form

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()
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jun 15th, 2008
2

Re: how to call another form

To call form2 you must to make an object of form2 :
VB.NET Syntax (Toggle Plain Text)
  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 :
VB.NET Syntax (Toggle Plain Text)
  1. Dim MainMenu as New Form2
  2. MainMenu.show
  3. Me.Dispose(False)
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007
Jun 19th, 2008
0

Re: how to call another form

Click to Expand / Collapse  Quote originally posted by tuse ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tirso is offline Offline
22 posts
since Jun 2008
Jun 19th, 2008
0

Re: how to call another form

thank you so much to all of your replied. It's worked. Until next post
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tirso is offline Offline
22 posts
since Jun 2008
Aug 14th, 2009
0

Re: how to call another form

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nrew123 is offline Offline
1 posts
since Aug 2009
Aug 15th, 2009
0

Re: how to call another form

in my oppinion the easiest way would be to create an overloaded New and call it with parameter (byval caller as From)
example:
vb Syntax (Toggle Plain Text)
  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)
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to clear the item listview when triggering a button
Next Thread in VB.NET Forum Timeline: Problem by writting the sql statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC