I want to use more than one form in my project and be able to code a button or something that will do that. I tried this on Form1 and it worked.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Goes from this form to form 2
        My.Forms.Form2.Show()
    End Sub

End Class

BUT then I tried the following on Form2 to go back to Form1 and it doesn't work... the button does nothing.

Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Forms.Form1.Show() 'Doesn't work

    End Sub
End Class

Also, when the user switches to a different form, will the variables assigned on the first form still be assigned on the second form (assuming they're declared as Public in the module?

Form1
Button Event
Me.Hide
Form2.Show

Form2
Button Event
Me.Hide
Form1.Show

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.