Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Keep Track of the Last Form

In your MDI application, you might have many child forms and need a form to go back to the form that called it. In each child form, declare this variable:
Public Callingform As Form
Before calling a form, set CallingForm to the form that is calling it so that the form being called can remember which form called it. Use this call to call a form:
ShowForm frmNextForm, Me
frmNextForm is the form that you're calling, and ShowForm is this Global Procedure (declared in a BAS file):
Sub ShowForm(frmFormToShow As Form, _
        frmFrom As Form)
        Set frmFormToShow.Callingform = _
End Sub
To close a form and go back to the form that called it, use this call:
ExitForm Callingform, Me
ExitForm is this global procedure:
Sub ExitForm(Callingform As Form, _
        ThisForm As Form)
        Unload ThisForm
End Sub
Use this procedure for all child forms except when you need to make the call from the main MDI form. In this case, use this call:
ShowChild frmChild

frmChild is the MDIChild form you're calling, and ShowChild is defined in the MDI form:

Private Sub ShowChild(frm As Form)
        Set frm.Callingform = frmMain
End Sub
It's a good idea to call procedures to do these tasks because you might want to put extra processing in these procedures. Note you should have error-handing routines as well in the procedures.
Sergio Walter
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date