+ Reply to Thread
Results 1 to 3 of 3

Passing Userform Listbox to sub causes type-mismatch error

  1. #1
    Kleev
    Guest

    Passing Userform Listbox to sub causes type-mismatch error

    I have a simple sub I created to verify this problem. When I send a Listbox
    from a userform as such: LBClear ListPuppyMo1, I get a type-mismatch error.
    Sub follows:
    Sub LBClear(lb As ListBox)
    lb.Clear
    End Sub
    When I debug the program and enter typename(listpuppymo1) it states that it
    is a listbox. It may be that they are 2 different types of listboxes, but if
    so, I cannot figure out how to specify that I want the lb parameter to be a
    userform listbox.

  2. #2
    Tom Ogilvy
    Guest

    Re: Passing Userform Listbox to sub causes type-mismatch error

    Sub LBClear(lb As MSForms.ListBox)
    lb.Clear
    End Sub

    Excel also has a listbox object which takes precedence - so you need to
    qualify

    --
    Regards,
    Tom Ogilvy



    "Kleev" <[email protected]> wrote in message
    news:[email protected]...
    > I have a simple sub I created to verify this problem. When I send a

    Listbox
    > from a userform as such: LBClear ListPuppyMo1, I get a type-mismatch

    error.
    > Sub follows:
    > Sub LBClear(lb As ListBox)
    > lb.Clear
    > End Sub
    > When I debug the program and enter typename(listpuppymo1) it states that

    it
    > is a listbox. It may be that they are 2 different types of listboxes, but

    if
    > so, I cannot figure out how to specify that I want the lb parameter to be

    a
    > userform listbox.




  3. #3
    sebastienm
    Guest

    RE: Passing Userform Listbox to sub causes type-mismatch error

    Hi,

    Use Sub LBClear(lb As MSForms.ListBox) instead.

    There are several types of listboxes, the one on the Forms toolbars that is
    intrinsic (i believe) to excel, and the one from the Control Toolbox toolbar
    from the MSForms library. So, in the parameter list of the Sub, without
    telling from which library the variable is from, vba assumes the lisbox
    intrinsic to excel... the wrong one in your case.

    --
    Regards,
    Sébastien
    <http://www.ondemandanalysis.com>


    "Kleev" wrote:

    > I have a simple sub I created to verify this problem. When I send a Listbox
    > from a userform as such: LBClear ListPuppyMo1, I get a type-mismatch error.
    > Sub follows:
    > Sub LBClear(lb As ListBox)
    > lb.Clear
    > End Sub
    > When I debug the program and enter typename(listpuppymo1) it states that it
    > is a listbox. It may be that they are 2 different types of listboxes, but if
    > so, I cannot figure out how to specify that I want the lb parameter to be a
    > userform listbox.


+ 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