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

  • Thread starter Cheryl & Mike Arsenault
  • Start date
C

Cheryl & Mike Arsenault

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
 
P

Per Jessen

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
 
J

Jim Cone

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
 
C

Cheryl & Mike Arsenault

Per Jessen said:
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

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

Mike
 
D

Dick Kusleika

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top