Consulting

Results 1 to 15 of 15

Thread: Solved: event manipulation and list boxes

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location

    Solved: event manipulation and list boxes

    ok i have too quetions.

    first how can i hide and then show a user forum without triggering the UserForm_Activate event?

    second. is there any way to tell how many items are selected in a list box, when the multi select property is set?

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I am not sure why you are wanting this and since you don't say....I guess you must be trying to put a userform out of sight and then recall it without it having lost the data you added when it was open the first time.? Is that about right?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    got it in one

    the forum requires you to give an input to auto cad, and as such it is easier if it gets out of the way. but afterwards i need it to come back in its new state, not its start state.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Create an activate method in your form, and clear out the Activate event, and call that when you first activate the form. That way you dictate when the activate code is invoked.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    For the other bit, you need to loop through counting the selected items.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    Quote Originally Posted by xld
    Create an activate method in your form, and clear out the Activate event, and call that when you first activate the form. That way you dictate when the activate code is invoked.
    i am not sure what you mean by an activate method. how would the code know to run it on oppeing if its not in the event module?

  7. #7
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    You could use a boolean the first time and set it to true when you initialize the form. On activating the form you check the value of that boolean. If boolean is true (means you have initalized it once) so don't do the beginning stuff but keep values.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What I mean is something like this in the form

    [vba]
    Private Sub UserForm_Activate()
    'do nothing
    End Sub

    Private Sub UserForm_Initialize()
    'do nothing
    End Sub

    Public Function Initialize() As Boolean
    Initialize = True
    On Error GoTo proc_error
    'do the things that you would normally do in the Initialize event

    proc_exit:
    Exit Function

    proc_error:
    Initialize = False
    Resume proc_exit
    End Function

    Public Function Activate() As Boolean
    Activate = True
    On Error GoTo proc_error
    'do the things that you would normally do in the activate event

    proc_exit:
    Exit Function

    proc_error:
    Activate = False
    Resume proc_exit
    End Function
    [/vba]

    and then you invoke the form like this

    [vba]

    Public Sub Test()
    Dim frm As UserForm1

    On Error GoTo proc_error
    Set frm = New UserForm1
    If Not frm.Initialize Then Err.Raise 19999
    If Not frm.Activate Then Err.Raise 19999
    frm.Show
    'when you come out ...
    '... do some stuff

    'then show form without the activate
    frm.Show

    '...

    proc_exit:
    Set frm = Nothing
    Exit Sub

    proc_error:
    'display error details
    Resume proc_exit

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    What's the purpose of not running the activate event?

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Read the thread.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Why not use the Initialiaze event instead of the Activate event?

    As far as I know it isn't triggered when you just show a userform.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is that asking of me or the OP?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    xld

    It's just a suggestion.

    Like I said as far as I'm aware the Initialize event isn't triggered when you show a userform.

    But the Activate event is.

    So if the problem is with the Activate event why not use the Initialize event instead?

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I understand the difference between Initialize and Activate, but I used Activate because, as I said earlier, ... That way you dictate when the activate code is invoked...

    If you look at my code as well, you will see that I allowed for Initialize and Activate code, so you have total control over when and where each or both is used. It ceases to be Initialize and Activate really, just two other methods. I stopped using the events and using custom methods some years ago when I was building an app that kept firing the Activate event and trying to stop it got far too complex, this method is simple and foolproof (AFAICS)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    thanks for all the help. its greatly appreciated.

Posting Permissions

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