If you want to use the same procedure, pass a parameter to proc to tell which form to show
Public Sub GotoForm(ByVal FormIndex As Integer)
' Change form
Select Case FormIndex
Case 2
frmLevel1.Close()
Dim frmLevel2 As Form2
frmLevel2 = New Form2
frmLevel2.Activate()
frmLevel2.Show()
Me.Hide()
Case 3
frmLevel2.Close()
Dim frmLevel3 As Form3
frmLevel3 = New Form3
frmLevel3.Activate()
frmLevel3.Show()
Me.Hide()
Case Else
' Wrong index
End Select
End Sub
and call it Start.GotoForm(2), Start.GotoForm(3) etc.
Without knowing more about your code I can't guarantee it works "as is", but I hope it gives you an idea how to do it.
HTH
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
Ok. Try to declare form variables global in your main form (Start form) i.e. where you have GotoForm. If you declare them inside the sub their scope will be only that sub and you "lose" the form reference when you exit the sub
' Globals in Start form
Private frmLevel1 As Form
Private frmLevel2 As Form
Private frmLevel3 As Form
.
.
Public Sub GotoForm(ByVal FormIndex As Integer)
' Change form
Select Case FormIndex
Case 2
' Additional check to avoid null reference error
If frmLevel1 IsNot Nothing Then
frmLevel1.Close()
End If
frmLevel2 = New Form2
frmLevel2.Activate()
frmLevel2.Show()
Me.Hide()
Case 3
' Additional check to avoid null reference error
If frmLevel2 IsNot Nothing Then
frmLevel2.Close()
End If
frmLevel3 = New Form3
frmLevel3.Activate()
frmLevel3.Show()
Me.Hide()
Case Else
' Wrong index
End Select
End Sub
I also added If <form> IsNot Nothing Then check just in case :)
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203