Link to home
Start Free TrialLog in
Avatar of mwwebb
mwwebb

asked on

run-time error '91' prevent mousewheel from browsing records

I want to prevent users from using the scroll wheel on a form in access. Two things can happen that i want to prevent. 1) If a user taps the scroll wheel accidently it clears the data they've entered in the fields without saving it. 2) This is for a survey, i dont want users to be able to scroll back and see what others have entered.  

I looked it up and found this code on a few different sites. Here's the actual link from MS http://support.microsoft.com/default.aspx?scid=kb;en-us;308636 .. Im using this on access 2000 and the article talks about access 97.  I didnt have to create the .dll mentioned in the top of the article, i downloaded it. Here's the second link i found regarding this http://www.techonthenet.com/access/forms/wheel.php .. this link is geared more towards access 2003/XP/2000/97. You'll notice it references the same code.

Below i've embedded the code snippets.  This code created an 'On Close' routine in the propeties of the form. When i close the program i get Run-Time error '91' .. Object variable or With block variable not set.   Ive tried adding error checking to catch the '91' and it does. Although it creates another problem. It closes access's GUI, but leaves it running in Task Manager. No one can reopen this DB without force quitting it through Task Manager first.

How do i get this code to work without generating errors (specifically '91'). Currently when it generates this error, the DB's GUI closes but MSACCESS.EXE remains open in the Task Manager. A users has to force quit MSACCESS.EXE before anyone can open that DB again.
^^^^^^^^^^^^^^^^^^^^^^^^Original Code^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Option Compare Database
Option Explicit
 
Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel
 
Private Sub Form_Load()
    Set clsMouseWheel = New MouseWheel.CMouseWheel
    Set clsMouseWheel.Form = Me
    clsMouseWheel.SubClassHookForm
End Sub
 
************Section that causes Run-Time error '91'*********
*  Private Sub Form_Close()                                *
*     clsMouseWheel.SubClassUnHookForm                     *
*     Set clsMouseWheel.Form = Nothing                     *
*     Set clsMouseWheel = Nothing                          *
*  End Sub                                                 *
************************************************************
 
 
Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
    MsgBox "You cannot use the mouse wheel to scroll records."
    Cancel = True
End Sub
 
^^^^^^^^^^^^^^^^^^^^^^^^Code with Error Routine^^^^^^^^^^^^^^^^^^^^^^
* This is the same code as circled above in stars. Except i've added an * error routine to drop out if anything happens (such as Run-Time 
* error '91').
**********************************************************************
Private Sub Form_Close()
On Error GoTo NextCmd
    clsMouseWheel.SubClassUnHookForm ' Q308636
    Set clsMouseWheel.Form = Nothing
    Set clsMouseWheel = Nothing
    
Exit_Form_Close:
    Exit Sub
 
NextCmd: Err = 0
    MsgBox Err.Description
    Resume Exit_Form_Close
       
End Sub

Open in new window

Avatar of fanopoe
fanopoe
Flag of United States of America image

make your form unbound so that they can't see other records. The scrollwheel is not the only way to get there.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mwwebb
mwwebb

ASKER

DatabaseMX,
Late yesterday afternoon I found this exact article and it is the solution to this problem.  I didnt see this mentioned, but in order for this to work, I had to export the modMouseHook module from the sample DB that is associated with the download. Then import it into my DB. This worked.  Without that module the .dll wouldnt perform the record locking I was looking for. Everything works as I want it to now, so thanks for your answer.
wow.  Cool ... you are welcome.

I have the MWH as a standard class in my Library.

mx
Avatar of mwwebb

ASKER

Its much better the MouseWheel.dll.  That file is atrocious to work with. The way you entered MWH as a standard class in your library, does that give the ability to use its functions on any new MDB you create w/o having to readd the Module to the app?
"does that give the ability to use its functions on any new MDB you create w/o having to readd the Module to the app?"

Exactly.

mx
Avatar of mwwebb

ASKER

Thanks mx.. you ace'd this one!