View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Why null reference to ListBox?

There are two different listboxes in excel. One if from the Forms toolbar and
is placed on a worksheet--or a dialog sheet.

The other is the activeX control listbox--from the control toolbox toolbar on a
worksheet - or on a userform.

And since they share the same ListBox name, you have to be more specific:

Sub CalledByClick(myListBox as msforms.listbox)
...
End sub

Sub lbox_change()
Call CalledByClick(mylistbox:=lbox)
or
call calledbyclick(lbox)
or
calledbyclick lbox
end sub

You've got to be specific with all those controls that share names. But it
doesn't hurt to be specific if if there isn't any ambiguity.

sub aaaa(myCBX as msforms.combobox)




Henry Markov wrote:

My UserForm has a ListBox control named lbox. In the click handler of
another control on the same form I call a subroutine that has lbox as one of
its parameters. I get a "Run-time error '13': Type mismatch" and when I go
to debug mode and float the cursor over "lbox" in the VBA code I see "lbox =
Null." However when I examine lbox in the "Locals" debug window it is well
defined. What don't I understand? How can break mode debugging give
different values for the same reference in different windows? Why did the
error occur?

HM


--

Dave Peterson