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

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()

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)
commented: great, this is No 1 hit in google search. +13

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

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

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.

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)

Member Avatar for SeniorAlexandro

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

Tax , it's very usefull for me

use dispose (false)
but after fomr 2 close, that application still running, so this can help " application.exit"
so all aplication form will be lose from memorry
i hope
that will be usefull :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.