Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Why Type Mismatch error David Excel Programming 5 July 23rd 05 02:37 AM
Reload Listbox - type mismatch error Stu[_34_] Excel Programming 3 July 14th 05 01:58 AM
Passing User Defined Type Array to Listbox PC[_4_] Excel Programming 2 June 1st 05 02:44 AM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 03:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"