Problem with ActiveX Mousewheel

M

Max Moor

Hi All,
Sorry for posting in the general group. I posted this in the ActiveX
group, but it looks like that group is all but extict. I thought I'd try
my luck.

I've used the MouseWheel control in the past without problem, but now
I have one. In trying to understand it, I came up with a question as well.
Here's both...

The Problem:

I use the control to make the mousewheel act on a listbox, called
lstGroup, that is on the form. The code I include in the form's module is
at the bottom of the post. Whenever I close the form, I get the error:

Runtime error '91':
Object variable or With block variable not set

If I select Debug, the debugger starts on the first line of the
Form_Deactivate code.

This is a form I've copied from a working app, with the MouseWheel
code identical. My concern is that I'm doing something horribly wrong, and
have just gotten lucky with my working app, which could explode at any
moment.

Can anyone tell me what I might be doing wrong?


The Question:

I looked up the use of "WithEvents," and the Visual Basic help says it
is only valid in class modules. Is a form module considered a class
module, or is that keyword not actually doing anything where I'm using it?


As always, thanks to the MVPs!

- Max



'''''''' Code At The Top Of The Form's Module ''''''''

Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel

Private Sub Form_Activate()
Set clsMouseWheel = New MouseWheel.CMouseWheel
Set clsMouseWheel.Form = Me
clsMouseWheel.SubClassHookForm
End Sub

Private Sub Form_Deactivate()
clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
End Sub

Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)

Dim ctlCurrent As Control

Set ctlCurrent = Screen.ActiveControl
If (ctlCurrent.Name <> "lstGroup") Then

Me!lstGroup.SetFocus
Cancel = True

End If
End Sub
 
M

Max Moor


Hi Douglas,

I looked at Stephen's code some time ago. It looks a much simpler
on/off switch, but I couldn't figure out how to use it to tie the mousewheel
to a specific control.

I don't want the mousewheel off, just to scroll a specific listbox on a
form, but never the main form itself. If the form scrolls, the controls go
blank. I noticed that even happens to the subform in Stephen's example
database.

- Max
 
M

Max Moor

Why not just grab what Stephen Lebans has at
http://www.lebans.com/mousewheelonoff.htm?

Hi Again,

Just after I hit send, it occurred to me that I wasn't quite clear. I
don't need the MouseWheel or MouseHook code to do the scrolling of the
listbox. I actually use the MouseWheel just to let me capture the Mousewheel
event when it occurs. I use code in the event to set the focus to the
listbox. That way any scroll of the Mousewheel gets focused on that listbox,
or other control.

I should have said that I didn't see how Stephen's code allowed my to
capture the Mousewheel event. (I'd love a better method than the MouseWheel
ActiveX control.)

- Max
 

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