Consulting

Results 1 to 5 of 5

Thread: Solved: Change focus or unload between forms

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location

    Solved: Change focus or unload between forms

    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

    [VBA]
    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
    [/VBA]

    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

    [VBA]
    Private Sub cmdClose_Click()
    Unload Me
    frmStartForm.Show
    End Sub
    [/VBA]

    Is this the correct method?

    Ted

  2. #2
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Are you asking because they don't work? They appear to be fine..

    you can also do:
    [VBA]

    Me.Hide
    frmStartForm.Show
    [/VBA]


    as an alternative.
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    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

  4. #4
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Quote Originally Posted by Aussiebear
    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.
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •