PDA

View Full Version : Solved: Change focus or unload between forms



Aussiebear
12-31-2006, 07:04 PM
Is it better practise when using a start form to select subsequent forms, that you unload the initial form or just lose the focus of the initial form.

What I'd like to do is change to a new form and not have the old form still sitting in the background, but then on closing the second form, return to the initial form.

Code on the StartForm is


Option Explicit
Private Sub cmdDelivery_Click()
frmDelivery.Show
End Sub
Private Sub cmdTransfer_Click()
frmTransfer.Show
End Sub
Private Sub cmdClose_Click()
Unload Me ' for use in closing the form and moving to the sheets for data checks. Will be made a subterfuge close later on as project develops
End Sub
Private Sub cmdExit_Click()
This workbook.Close ' Save and Exit workbook
End Sub


When I bring up the secondary forms ( Deliveries & Transfers), I'd like the Startform to lose its visibility, and then on closing the secondary forms to be returned to the StartForm.

Example: FrmDelivery close button


Private Sub cmdClose_Click()
Unload Me
frmStartForm.Show
End Sub


Is this the correct method?

Ted

XLGibbs
12-31-2006, 07:45 PM
Are you asking because they don't work? They appear to be fine..

you can also do:


Me.Hide
frmStartForm.Show



as an alternative.

Aussiebear
12-31-2006, 08:00 PM
No. I was asking if they are correct? I'd been sitting here working on the Parent Child spreadsheet when it occured to me that this might be the way to go.

Since you raise the point about Me.Hide, does this just turn off the visibility yet it remains loaded into the memory?

Ted

XLGibbs
12-31-2006, 10:36 PM
No. I was asking if they are correct? I'd been sitting here working on the Parent Child spreadsheet when it occured to me that this might be the way to go.

Since you raise the point about Me.Hide, does this just turn off the visibility yet it remains loaded into the memory?

Ted

Yes, .Hide keeps them loaded in memory, but makes them invisible.

Bob Phillips
01-01-2007, 09:00 AM
In most circumstances, if you have a child form(s) it makes sense to leave the parent form(s) still in memory. Either hide it from the child form, or just leave it. This way you can more easily pass information/data bewtwwn the forms.

As mentioned, Unload takes it out of memory, Hide makes it non-visible but leaves it in memory. There is never a need to issue a Load command, because if it is not in memory, Show will also load it. One other thing to be aware of is that the Userform_Initialize event is triggered on a load, the Activate on a Show, so they both get invoked if the form is not in memory, only Activate if it is in memory.