Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Can't pass a ListBox as a ListBox - must be a Variant??

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Can't pass a ListBox as a ListBox - must be a Variant??

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

"Cheryl & Mike Arsenault" skrev i meddelelsen
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Can't pass a ListBox as a ListBox - must be a Variant??


How are the variables POLines and AddPSLines declared?
The type declarations in the called sub should be the same as the original type declarations.
--
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Can't pass a ListBox as a ListBox - must be a Variant??


"Per Jessen" wrote in message
...
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

"Cheryl & Mike Arsenault" skrev i meddelelsen
...
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



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

Mike


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Can't pass a ListBox as a ListBox - must be a Variant??

On Sat, 22 Mar 2008 06:38:27 -0400, "Cheryl & Mike Arsenault"
wrote:

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


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.
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com
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
Pass listbox values to autofilter Ixtreme Excel Programming 5 August 25th 07 01:45 PM
Pass a form Listbox as an object Brian Excel Programming 2 November 18th 05 11:51 PM
How do I pass an array to a listbox? Titus A Ducksass - AKA broken-record Excel Programming 4 March 23rd 05 07:20 PM
How to pass ListBox into a Sub? RADO[_3_] Excel Programming 2 November 16th 03 08:22 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 11:56 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"