View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Henry Markov Henry Markov is offline
external usenet poster
 
Posts: 4
Default Why null reference to ListBox?

Dave,
According to your explanation I was specific. I said my control was on a
UserForm. Your explanation says that the ListBox on a UserForm is the
ActiveX variety. I'm just an occasional VBA programmer so I'm often
ignorant of all the obsfucation in MS development tools such as giving two
different objects used within the same application the same name. I get to
Excel VBA from a worksheet through Tools-Macro-Visual Basic Editor. I
create modules and user forms. I drag controls onto the user forms from the
little Toolbox.

Note: I don't know what your code is supposed to be telling me.

HM

"Dave Peterson" wrote in message
...
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