Cancel Button

I can currently access form "A" through form "B" or form "C".  I have a cancel button on form "A" which when clicked I would like it to return me to the form that I was using previously.  How can I code this cancel button to take me to the form I was previously on before going to form "A".  Any help would be appreciated.

 P.S.  I am using form show - form hide to do this.  
jakemailAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Erick37Connect With a Mentor Commented:
In a MODULE put a global variable to hold the previous form as:

Public PrevFrm as Form

Then in the main form code:

Private Sub Command1_Click()
    Debug.Print PrevFrm.Name
End Sub

Private Sub Form_Deactivate()
    Set PrevFrm = Me
End Sub

Private Sub Form_Load()
    Set PrevFrm = Me
    Form2.Show
    Form3.Show
End Sub

And in each of the other forms use:

Private Sub Form_Deactivate()
    Set PrevFrm = Me
End Sub
0
 
KurvyCommented:

Instead of using a load event, create a Public Sub as follows
declare a form level variable
dim fLastForm as form

Public Sub Start(frmCall as form)

set flastform=frmcall
flastform.hide

**whatever code you need to start on your form**

me.show

End sub

in the unload event of the form
add the line

flastform.show
0
All Courses

From novice to tech pro — start learning today.