+ Reply to Thread
Results 1 to 11 of 11

couple userform questions

  1. #1
    Gary Keramidas
    Guest

    couple userform questions

    1) when the close(x) closes a form, does it create any kind of event to act on?

    2) let's say you use a form as a main menu. clicking a command button loads a
    submenu, so you either hide or unload the main menu.
    the operation the 2nd command button launches takes x amount of time.
    how can you load the main menu after the operation is completed?

    --


    Gary




  2. #2
    Harald Staff
    Guest

    Re: couple userform questions

    Hi Gary

    Demo:
    Userform1 with Commandbutton1 and Commandbutton2.
    Userform2 with Commandbutton1.

    Userform1 code:

    '***************************************
    Option Explicit

    Private Sub UserForm_Initialize()
    CommandButton1.Caption = "Proceed"
    CommandButton2.Caption = "Exit"
    End Sub

    Private Sub CommandButton1_Click()
    Me.Hide
    UserForm2.Show
    End Sub

    Private Sub CommandButton2_Click()
    Unload Me
    End Sub

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    MsgBox "Close mode is " & CloseMode
    End Sub
    '*******************************************

    userform2 code:
    '*******************************************

    Option Explicit

    Private Sub CommandButton1_Click()
    Dim i As Long, j As Long
    For i = 1 To 3000
    Me.Caption = i
    For j = 1 To 10000
    Next
    Next
    Unload Me
    UserForm1.Show
    End Sub
    '*******************************************

    Try the X on userform1.

    HTH. Best wishes Harald


    "Gary Keramidas" <GKeramidasATmsn.com> skrev i melding
    news:[email protected]...
    > 1) when the close(x) closes a form, does it create any kind of event to

    act on?
    >
    > 2) let's say you use a form as a main menu. clicking a command button

    loads a
    > submenu, so you either hide or unload the main menu.
    > the operation the 2nd command button launches takes x amount of time.
    > how can you load the main menu after the operation is completed?
    >
    > --
    >
    >
    > Gary
    >
    >
    >




  3. #3

    Re: couple userform questions

    Hi Gary,

    Perhaps you can use SaveSetting function ... like :

    Dim r
    Private Sub UserForm_Activate()
    r = GetSetting("App", "Sect", "Ky")
    If r = "" Then
    r = 0
    Exit Sub
    Else
    MsgBox "You've closed " & r & " times!"
    End If
    End Sub

    Private Sub UserForm_Terminate()
    SaveSetting "App", "Sect", "Ky", Val(r) + 1
    End Sub

    Rgds,

    Halim




    Gary Keramidas menuliskan:
    > 1) when the close(x) closes a form, does it create any kind of event to act on?
    >
    > 2) let's say you use a form as a main menu. clicking a command button loads a
    > submenu, so you either hide or unload the main menu.
    > the operation the 2nd command button launches takes x amount of time.
    > how can you load the main menu after the operation is completed?
    >
    > --
    >
    >
    > Gary



  4. #4
    Gary Keramidas
    Guest

    Re: couple userform questions

    thanks for the code harald.

    regarding the "x". what i want to know, is how can i trap if someone clicks
    the "x"?


    Gary


    --


    Gary


    "Harald Staff" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi Gary
    >
    > Demo:
    > Userform1 with Commandbutton1 and Commandbutton2.
    > Userform2 with Commandbutton1.
    >
    > Userform1 code:
    >
    > '***************************************
    > Option Explicit
    >
    > Private Sub UserForm_Initialize()
    > CommandButton1.Caption = "Proceed"
    > CommandButton2.Caption = "Exit"
    > End Sub
    >
    > Private Sub CommandButton1_Click()
    > Me.Hide
    > UserForm2.Show
    > End Sub
    >
    > Private Sub CommandButton2_Click()
    > Unload Me
    > End Sub
    >
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > MsgBox "Close mode is " & CloseMode
    > End Sub
    > '*******************************************
    >
    > userform2 code:
    > '*******************************************
    >
    > Option Explicit
    >
    > Private Sub CommandButton1_Click()
    > Dim i As Long, j As Long
    > For i = 1 To 3000
    > Me.Caption = i
    > For j = 1 To 10000
    > Next
    > Next
    > Unload Me
    > UserForm1.Show
    > End Sub
    > '*******************************************
    >
    > Try the X on userform1.
    >
    > HTH. Best wishes Harald
    >
    >
    > "Gary Keramidas" <GKeramidasATmsn.com> skrev i melding
    > news:[email protected]...
    >> 1) when the close(x) closes a form, does it create any kind of event to

    > act on?
    >>
    >> 2) let's say you use a form as a main menu. clicking a command button

    > loads a
    >> submenu, so you either hide or unload the main menu.
    >> the operation the 2nd command button launches takes x amount of time.
    >> how can you load the main menu after the operation is completed?
    >>
    >> --
    >>
    >>
    >> Gary
    >>
    >>
    >>

    >
    >




  5. #5
    Ron de Bruin
    Guest

    Re: couple userform questions

    Hi Gary

    Use this then in the userform

    Private Sub UserForm_QueryClose(Cancel As Integer, _
    CloseMode As Integer)
    If CloseMode <> vbFormCode Then
    MsgBox "Use the Close button to close the form.", _
    vbOKOnly, "program name"
    Cancel = True
    End If
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Gary Keramidas" <GKeramidasATmsn.com> wrote in message news:[email protected]...
    > thanks for the code harald.
    >
    > regarding the "x". what i want to know, is how can i trap if someone clicks
    > the "x"?
    >
    >
    > Gary
    >
    >
    > --
    >
    >
    > Gary
    >
    >
    > "Harald Staff" <[email protected]> wrote in message news:%[email protected]...
    >> Hi Gary
    >>
    >> Demo:
    >> Userform1 with Commandbutton1 and Commandbutton2.
    >> Userform2 with Commandbutton1.
    >>
    >> Userform1 code:
    >>
    >> '***************************************
    >> Option Explicit
    >>
    >> Private Sub UserForm_Initialize()
    >> CommandButton1.Caption = "Proceed"
    >> CommandButton2.Caption = "Exit"
    >> End Sub
    >>
    >> Private Sub CommandButton1_Click()
    >> Me.Hide
    >> UserForm2.Show
    >> End Sub
    >>
    >> Private Sub CommandButton2_Click()
    >> Unload Me
    >> End Sub
    >>
    >> Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    >> MsgBox "Close mode is " & CloseMode
    >> End Sub
    >> '*******************************************
    >>
    >> userform2 code:
    >> '*******************************************
    >>
    >> Option Explicit
    >>
    >> Private Sub CommandButton1_Click()
    >> Dim i As Long, j As Long
    >> For i = 1 To 3000
    >> Me.Caption = i
    >> For j = 1 To 10000
    >> Next
    >> Next
    >> Unload Me
    >> UserForm1.Show
    >> End Sub
    >> '*******************************************
    >>
    >> Try the X on userform1.
    >>
    >> HTH. Best wishes Harald
    >>
    >>
    >> "Gary Keramidas" <GKeramidasATmsn.com> skrev i melding
    >> news:[email protected]...
    >>> 1) when the close(x) closes a form, does it create any kind of event to

    >> act on?
    >>>
    >>> 2) let's say you use a form as a main menu. clicking a command button

    >> loads a
    >>> submenu, so you either hide or unload the main menu.
    >>> the operation the 2nd command button launches takes x amount of time.
    >>> how can you load the main menu after the operation is completed?
    >>>
    >>> --
    >>>
    >>>
    >>> Gary
    >>>
    >>>
    >>>

    >>
    >>

    >
    >




  6. #6
    Bob Phillips
    Guest

    Re: couple userform questions

    That was the QueryClose event

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    MsgBox "Close mode is " & CloseMode
    End Sub

    from help

    Occurs before a UserForm closes.

    Syntax

    Private Sub UserForm_QueryClose(cancel As Integer, closemode As Integer)

    The QueryClose event syntax has these parts:

    Part Description
    cancel An integer. Setting this argument to any value other than 0
    stops the QueryClose event in all loaded user forms and prevents the
    UserForm and application from closing.
    closemode A value or constant indicating the cause of the QueryClose
    event.



    Return Values

    The closemode argument returns the following values:

    Constant Value Description
    vbFormControlMenu 0 The user has chosen the Close command from the
    Control menu on the UserForm.
    vbFormCode 1 The Unload statement is invoked from code.
    vbAppWindows 2 The current Windows operating environment session is
    ending.
    vbAppTaskManager 3 The Windows Task Manager is closing the
    application.



    These constants are listed in the Visual Basic for Applications object
    library in the Object Browser. Note that vbFormMDIForm is also specified in
    the Object Browser, but is not yet supported.

    Remarks

    This event is typically used to make sure there are no unfinished tasks in
    the user forms included in an application before that application closes.
    For example, if a user hasn't saved new data in any UserForm, the
    application can prompt the user to save the data.

    When an application closes, you can use the QueryClose event procedure to
    set the Cancel property to True, stopping the closing process.




    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
    news:[email protected]...
    > thanks for the code harald.
    >
    > regarding the "x". what i want to know, is how can i trap if someone

    clicks
    > the "x"?
    >
    >
    > Gary
    >
    >
    > --
    >
    >
    > Gary
    >
    >
    > "Harald Staff" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Hi Gary
    > >
    > > Demo:
    > > Userform1 with Commandbutton1 and Commandbutton2.
    > > Userform2 with Commandbutton1.
    > >
    > > Userform1 code:
    > >
    > > '***************************************
    > > Option Explicit
    > >
    > > Private Sub UserForm_Initialize()
    > > CommandButton1.Caption = "Proceed"
    > > CommandButton2.Caption = "Exit"
    > > End Sub
    > >
    > > Private Sub CommandButton1_Click()
    > > Me.Hide
    > > UserForm2.Show
    > > End Sub
    > >
    > > Private Sub CommandButton2_Click()
    > > Unload Me
    > > End Sub
    > >
    > > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > > MsgBox "Close mode is " & CloseMode
    > > End Sub
    > > '*******************************************
    > >
    > > userform2 code:
    > > '*******************************************
    > >
    > > Option Explicit
    > >
    > > Private Sub CommandButton1_Click()
    > > Dim i As Long, j As Long
    > > For i = 1 To 3000
    > > Me.Caption = i
    > > For j = 1 To 10000
    > > Next
    > > Next
    > > Unload Me
    > > UserForm1.Show
    > > End Sub
    > > '*******************************************
    > >
    > > Try the X on userform1.
    > >
    > > HTH. Best wishes Harald
    > >
    > >
    > > "Gary Keramidas" <GKeramidasATmsn.com> skrev i melding
    > > news:[email protected]...
    > >> 1) when the close(x) closes a form, does it create any kind of event to

    > > act on?
    > >>
    > >> 2) let's say you use a form as a main menu. clicking a command button

    > > loads a
    > >> submenu, so you either hide or unload the main menu.
    > >> the operation the 2nd command button launches takes x amount of time.
    > >> how can you load the main menu after the operation is completed?
    > >>
    > >> --
    > >>
    > >>
    > >> Gary
    > >>
    > >>
    > >>

    > >
    > >

    >
    >




  7. #7
    Harald Staff
    Guest

    Re: couple userform questions

    Bob explained the theory. I told you to try it and I guess you didn't. Many
    people refuse to try a solution they don't immediately understand. That is
    not a good approach. Most solutions to anything are complicated and
    illogical, but they work anyway.

    Best wishes Harald

    "Harald Staff" <[email protected]> skrev i melding
    news:%[email protected]...
    > Hi Gary


    > Try the X on userform1.




  8. #8
    Gary Keramidas
    Guest

    Re: couple userform questions

    harald:

    i did try it. i know you know a lot more than i'll ever know. what i was looking
    for was a simple, built in way. i thought there may be a method i didn't know
    about. why isn't there a built in option, just like show, hide, activate? every
    userform has an x,
    figured if the x was clicked, the userform was closed and it could be acted on
    without writing code
    to do it.




    --


    Gary


    "Harald Staff" <[email protected]> wrote in message
    news:[email protected]...
    > Bob explained the theory. I told you to try it and I guess you didn't. Many
    > people refuse to try a solution they don't immediately understand. That is
    > not a good approach. Most solutions to anything are complicated and
    > illogical, but they work anyway.
    >
    > Best wishes Harald
    >
    > "Harald Staff" <[email protected]> skrev i melding
    > news:%[email protected]...
    >> Hi Gary

    >
    >> Try the X on userform1.

    >
    >






  9. #9
    Bob Phillips
    Guest

    Re: couple userform questions

    Gary

    The problem is that when the x is clicked, the form is unloaded, so there is
    nothing to test against. Therefore you have to trap the close event, which
    is what Query Close gives you.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
    news:[email protected]...
    > harald:
    >
    > i did try it. i know you know a lot more than i'll ever know. what i was

    looking
    > for was a simple, built in way. i thought there may be a method i didn't

    know
    > about. why isn't there a built in option, just like show, hide, activate?

    every
    > userform has an x,
    > figured if the x was clicked, the userform was closed and it could be

    acted on
    > without writing code
    > to do it.
    >
    >
    >
    >
    > --
    >
    >
    > Gary
    >
    >
    > "Harald Staff" <[email protected]> wrote in message
    > news:[email protected]...
    > > Bob explained the theory. I told you to try it and I guess you didn't.

    Many
    > > people refuse to try a solution they don't immediately understand. That

    is
    > > not a good approach. Most solutions to anything are complicated and
    > > illogical, but they work anyway.
    > >
    > > Best wishes Harald
    > >
    > > "Harald Staff" <[email protected]> skrev i melding
    > > news:%[email protected]...
    > >> Hi Gary

    > >
    > >> Try the X on userform1.

    > >
    > >

    >
    >
    >
    >




  10. #10
    Gary Keramidas
    Guest

    Re: couple userform questions

    thanks for the explanation. as i mentioned, i don't know near as much as you
    guys do.

    --


    Gary


    "Bob Phillips" <[email protected]> wrote in message
    news:%23B8EVH%[email protected]...
    > Gary
    >
    > The problem is that when the x is clicked, the form is unloaded, so there is
    > nothing to test against. Therefore you have to trap the close event, which
    > is what Query Close gives you.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Gary Keramidas" <GKeramidasATmsn.com> wrote in message
    > news:[email protected]...
    >> harald:
    >>
    >> i did try it. i know you know a lot more than i'll ever know. what i was

    > looking
    >> for was a simple, built in way. i thought there may be a method i didn't

    > know
    >> about. why isn't there a built in option, just like show, hide, activate?

    > every
    >> userform has an x,
    >> figured if the x was clicked, the userform was closed and it could be

    > acted on
    >> without writing code
    >> to do it.
    >>
    >>
    >>
    >>
    >> --
    >>
    >>
    >> Gary
    >>
    >>
    >> "Harald Staff" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Bob explained the theory. I told you to try it and I guess you didn't.

    > Many
    >> > people refuse to try a solution they don't immediately understand. That

    > is
    >> > not a good approach. Most solutions to anything are complicated and
    >> > illogical, but they work anyway.
    >> >
    >> > Best wishes Harald
    >> >
    >> > "Harald Staff" <[email protected]> skrev i melding
    >> > news:%[email protected]...
    >> >> Hi Gary
    >> >
    >> >> Try the X on userform1.
    >> >
    >> >

    >>
    >>
    >>
    >>

    >
    >




  11. #11
    Harald Staff
    Guest

    Re: couple userform questions

    Hi Gary

    Glad it worked out in the end.
    I wasn't trying to be smart or rude, I just believed my demo was simple and
    to the point. Apologies if it wasn't so.

    Best wishes Harald

    "Gary Keramidas" <GKeramidasATmsn.com> skrev i melding
    news:eeZH%23i%[email protected]...
    > thanks for the explanation. as i mentioned, i don't know near as much as

    you
    > guys do.
    >
    > --
    >
    >
    > Gary




+ 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