Moving between forms

I havee 5 forms.

1. Main form with "ok" button
2. Form 1 with next button
3. Form 2 with next and previous button
4. Form 3 with next and previous button
5. Form 4 with next and done button


If user puts relavent information in "main form" he goes to form1 then and thus can enter relavent information between form1-form4. During that period if the user moves between form the values input are preserved. When the done button is clicked on form4 user goes back to mainform with an option to "add another record". Now here is my problem on mainform when user clicks on "ok" button, the first form comes as blank, however rest all the rest will show the same values that were typred in for previous record. And this happens for form2,3 and 4 all use previous values typed in for last record. I need it to be coming out blank. How can i do that? The code i am using isbelow.





Module Module1
    Public f1 As new Form1
    Public f2 As New Form2
    Public f3 As New Form3
    Public f4 As New Form4

End Module

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        f1 = Me
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Me.Hide()
        f2.Show()
    End Sub

End Class

Public Class Form2
    Inherits System.Windows.Forms.Form

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Me.Hide()
        f3.Show()
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        Me.Hide()
        f1.Show()
    End Sub

End Class

Public Class Form3
    Inherits System.Windows.Forms.Form

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Me.Hide()
        f4.Show()
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        Me.Hide()
        f2.Show()
    End Sub

End Class

Public Class Form4
    Inherits System.Windows.Forms.Form

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        Me.Hide()
        f3.Show()
    End Sub

    Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
        ' access the public, global variables f1, f2, f3 and f4 here
        ' to save all the data...

     
    End Sub

End Class

 

LVL 1
janjuama84Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MacNuttinCommented:
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
        ' access the public, global variables f1, f2, f3 and f4 here
        ' to save all the data...
f2 = nothing
f3 = nothing
f4 = nothing
janjuama84Author Commented:
When i do this again, form1 loads fine, however, when i click on the next button on form1 i get message "object reference not set to an instance of an object"
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
When the user clicks the "Add Another Record" button, you need to make new forms:

    f1 = New Form1
    f2 = New Form2
    f3 = New Form3
    f4 = New Form4
    f1.Show()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MacNuttinCommented:
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
        ' access the public, global variables f1, f2, f3 and f4 here
        ' to save all the data...
        Me.Close()
        f1.TextBox1.Text = ""
        f2.TextBox1.Text = ""
        f3.TextBox1.Text = ""
        f4.TextBox1.Text = ""
        Module1.f1.Show()
    End Sub

'also add this to form1:

Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
        Me.Close()
    End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.