+ Reply to Thread
Results 1 to 6 of 6

load/unload userform

  1. #1
    Fred
    Guest

    load/unload userform

    I have created a userform with an Initialize event that loads the userform
    from a database.
    To use the form I run

    Load myForm
    myForm.Show
    Unload myForm

    The form has an OK Button and a Cancel button which both hide the form and
    then the next line of code unloads (terminates) the form.

    It all works OK except when the user closes the form by clicking the form's
    close button (top right cross).
    When this happens the form actually terminates so when the Unload myForm
    code runs, because myForm has been terminated it is first re-initialized
    before it is then terminated.
    Although there are no errors and it still works OK it is annoying as the
    initialize event downloads quite e bit of data and so takes quite a while.

    Is there any way I can find out if myForm has been terminated before I run
    the Unload command.

    Thanks,
    Fred



  2. #2
    Nigel
    Guest

    Re: load/unload userform

    Not sure if it will help but I use the following test to control the
    switching between two overlayed forms......
    If the form is not initialized this will return false as well.

    UserForm1.Visible = True

    --
    Cheers
    Nigel



    "Fred" <nospam@please.com> wrote in message
    news:ufH%23eFgpFHA.2692@TK2MSFTNGP10.phx.gbl...
    > I have created a userform with an Initialize event that loads the userform
    > from a database.
    > To use the form I run
    >
    > Load myForm
    > myForm.Show
    > Unload myForm
    >
    > The form has an OK Button and a Cancel button which both hide the form and
    > then the next line of code unloads (terminates) the form.
    >
    > It all works OK except when the user closes the form by clicking the

    form's
    > close button (top right cross).
    > When this happens the form actually terminates so when the Unload myForm
    > code runs, because myForm has been terminated it is first re-initialized
    > before it is then terminated.
    > Although there are no errors and it still works OK it is annoying as the
    > initialize event downloads quite e bit of data and so takes quite a while.
    >
    > Is there any way I can find out if myForm has been terminated before I run
    > the Unload command.
    >
    > Thanks,
    > Fred
    >
    >




  3. #3
    Bob Phillips
    Guest

    Re: load/unload userform

    Fred,

    You can trap that event, and cancel it

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then
    Cancel = True
    End If
    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Nigel" <nigel-sw@suxnospampanet.com> wrote in message
    news:eCnpN7gpFHA.1996@TK2MSFTNGP10.phx.gbl...
    > Not sure if it will help but I use the following test to control the
    > switching between two overlayed forms......
    > If the form is not initialized this will return false as well.
    >
    > UserForm1.Visible = True
    >
    > --
    > Cheers
    > Nigel
    >
    >
    >
    > "Fred" <nospam@please.com> wrote in message
    > news:ufH%23eFgpFHA.2692@TK2MSFTNGP10.phx.gbl...
    > > I have created a userform with an Initialize event that loads the

    userform
    > > from a database.
    > > To use the form I run
    > >
    > > Load myForm
    > > myForm.Show
    > > Unload myForm
    > >
    > > The form has an OK Button and a Cancel button which both hide the form

    and
    > > then the next line of code unloads (terminates) the form.
    > >
    > > It all works OK except when the user closes the form by clicking the

    > form's
    > > close button (top right cross).
    > > When this happens the form actually terminates so when the Unload myForm
    > > code runs, because myForm has been terminated it is first re-initialized
    > > before it is then terminated.
    > > Although there are no errors and it still works OK it is annoying as the
    > > initialize event downloads quite e bit of data and so takes quite a

    while.
    > >
    > > Is there any way I can find out if myForm has been terminated before I

    run
    > > the Unload command.
    > >
    > > Thanks,
    > > Fred
    > >
    > >

    >
    >




  4. #4
    Fred
    Guest

    Re: load/unload userform

    Thanks Bob,
    that works fine.


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:uXI95xipFHA.4056@TK2MSFTNGP10.phx.gbl...
    > Fred,
    >
    > You can trap that event, and cancel it
    >
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > If CloseMode = 0 Then
    > Cancel = True
    > End If
    > End Sub
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Nigel" <nigel-sw@suxnospampanet.com> wrote in message
    > news:eCnpN7gpFHA.1996@TK2MSFTNGP10.phx.gbl...
    >> Not sure if it will help but I use the following test to control the
    >> switching between two overlayed forms......
    >> If the form is not initialized this will return false as well.
    >>
    >> UserForm1.Visible = True
    >>
    >> --
    >> Cheers
    >> Nigel
    >>
    >>
    >>
    >> "Fred" <nospam@please.com> wrote in message
    >> news:ufH%23eFgpFHA.2692@TK2MSFTNGP10.phx.gbl...
    >> > I have created a userform with an Initialize event that loads the

    > userform
    >> > from a database.
    >> > To use the form I run
    >> >
    >> > Load myForm
    >> > myForm.Show
    >> > Unload myForm
    >> >
    >> > The form has an OK Button and a Cancel button which both hide the form

    > and
    >> > then the next line of code unloads (terminates) the form.
    >> >
    >> > It all works OK except when the user closes the form by clicking the

    >> form's
    >> > close button (top right cross).
    >> > When this happens the form actually terminates so when the Unload
    >> > myForm
    >> > code runs, because myForm has been terminated it is first
    >> > re-initialized
    >> > before it is then terminated.
    >> > Although there are no errors and it still works OK it is annoying as
    >> > the
    >> > initialize event downloads quite e bit of data and so takes quite a

    > while.
    >> >
    >> > Is there any way I can find out if myForm has been terminated before I

    > run
    >> > the Unload command.
    >> >
    >> > Thanks,
    >> > Fred
    >> >
    >> >

    >>
    >>

    >
    >




  5. #5
    Registered User
    Join Date
    11-21-2016
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    1

    Re: load/unload userform

    syntax -----------

    !!!!!


    --



    UnloadMe
    Load frmxxxxx@
    frmxxxx.Show

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: load/unload userform

    Jamal, what was the purpose of your post here?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1