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
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