janjuama84
asked on
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
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
ASKER
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
' 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
' access the public, global variables f1, f2, f3 and f4 here
' to save all the data...
f2 = nothing
f3 = nothing
f4 = nothing