Closing Form1 from Form18

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
I am having a problem closing Form1 from form18. The application has 18 forms. Starting at Form1 (the sign-in form), you make various selections from all 16 additional forms in sequence. To go from one form to the next you click a continue button that closes the ME form and opens the next form. Each form is closed when you leave it to go on to the next one, except Form1. This one isn't close. When you get to Form18 and finish it, you then click on a close button, which closes Form18 and now the user sees Form1. How can I close Form1 when I click on the Close button on Form18? I tried doing a perform click on the close button on Form1 when the user clicks on the close button on Form18. But that doesn't work. The reason I wanted Form1 still open is that when the user closes Form18 I wanted to give the user the option of starting again with a new sign in.

Your time is appreciated.

John M
 
Form1 Error

Here's my code from form18. The statement Form1.close gives me an error "form1 not declared"

John M

Private
Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Dim SaveorNot As DialogResult
'Flagsave =0 then selections haven't been saved
' if =1 then they were saved already
If FlagSave = 0 Then
SaveorNot = MessageBox.Show("Do you want to save your current changes before you exit?", "Your selections not saved!", MessageBoxButtons.YesNoCancel)
If SaveorNot = DialogResult.Cancel Then
Exit Sub
ElseIf SaveorNot = DialogResult.Yes Then
btnSave.Focus()
btnSave.PerformClick()
Exit Sub
ElseIf SaveorNot = DialogResult.No Then
Me.Close()
Me.Dispose()
End If
Else
Me.Close()
Me.Dispose()
End If
form1.Close()
End Sub
 
Form 1 just loading it

I open Form1 just by creating it. I was reading more on this and this form1 is the start up form for the application. I think that's why I can't close it before I start progressing through forms1 to 18. I guess the better question I should have asked is how can I end the application from form18 while form1 is still open?

Thank you for your time

John M
 
Found a solution

I kept reading more of this forum and found that form1 is the start up form so I can't close it because if I did the application would end. But I needed to close it from the last form but I got a "not declared" error when I tried. By creating a module and setting it to Friend Scope and putting in a variable (EX. testform1) referencing form1 I would be able to access form1 from any of the other forms. Adding "testform1.dispose" to the exit button on the last form, close form1. I tested it and it works.

Thank you for the insight.

John M
 
Back
Top