Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Can't pass a ListBox as a ListBox - must be a Variant??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cheryl & Mike Arsenault - 22 Mar 2008 11:38 GMT
Please have a look at the 2 subs below

Private Sub POLines_Change()
   UpdateTransferButton POLines, AddPSLines
End Sub

Private Sub UpdateTransferButton(ByRef lb As ListBox, ByRef b As
CommandButton)
   Dim index As Integer
   For index = 0 To lb.ListCount - 1
       If lb.Selected(index) Then
           b.Enabled = True
           Exit Sub
       End If
   Next
   b.Enabled = False
End Sub

From the first subroutine, I'm trying to call the second one, which takes as
parameters a ListBox and a CommandButton. I'm getting a runtime error on the
call form the first subroutine indicating that I have type mismatch. Can
someone tell me why??

When I change the 2 parameters to Variants, everything is OK.

Why can't I pass a ListBox as a ListBox and same with a CommandButton

Thanks
Mike
Per Jessen - 22 Mar 2008 11:54 GMT
Hi

You have to use the named arguments:

Private Sub POLines_Change()
   Call UpdateTransferButton(lb:=POLines, b:=AddPSLines)
End Sub

or

Private Sub POLines_Change()
    UpdateTransferButton lb:=POLines, b:=AddPSLines
End Sub

Regards,

Per

> Please have a look at the 2 subs below
>
[quoted text clipped - 25 lines]
> Thanks
> Mike
Cheryl & Mike Arsenault - 24 Mar 2008 03:11 GMT
> Hi
>
[quoted text clipped - 43 lines]
>> Thanks
>> Mike

Thanks for the suggestion, but I tried that with no effect - still get Type
Mismatch!!

Mike
Jim Cone - 22 Mar 2008 14:24 GMT
How are the variables POLines and AddPSLines declared?
The type declarations in the called sub should be the same as the original type declarations.
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Cheryl & Mike Arsenault"
wrote in message
Please have a look at the 2 subs below

Private Sub POLines_Change()
   UpdateTransferButton POLines, AddPSLines
End Sub

Private Sub UpdateTransferButton(ByRef lb As ListBox, ByRef b As
CommandButton)
   Dim index As Integer
   For index = 0 To lb.ListCount - 1
       If lb.Selected(index) Then
           b.Enabled = True
           Exit Sub
       End If
   Next
   b.Enabled = False
End Sub

From the first subroutine, I'm trying to call the second one, which takes as
parameters a ListBox and a CommandButton. I'm getting a runtime error on the
call form the first subroutine indicating that I have type mismatch. Can
someone tell me why??

When I change the 2 parameters to Variants, everything is OK.
Why can't I pass a ListBox as a ListBox and same with a CommandButton
Thanks
Mike

Dick Kusleika - 24 Mar 2008 04:05 GMT
>Please have a look at the 2 subs below
>
[quoted text clipped - 22 lines]
>
>Why can't I pass a ListBox as a ListBox and same with a CommandButton

In addition to the other responses, sometimes there's a conflict between
classes with the same names.  Try calling out those arguments as

MSForms.ListBox
MSForms.CommandButton

and see if that takes care of it.
Signature

Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.