INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

User Interface Techniques

How to prevent users from leaving current record by scrolling the Mouse Wheel by jollygood
Posted: 30 Jun 04 (Edited 4 Oct 04)

If you have made a form where you don't whant your users to be able to scroll between records using the Mouse Wheel then this is for you.
For those of you who have been here before. There are important changes in this faq.

This technique only works in "Form View" and I have only tried it on Access 2002/XP.

Step 1.
On your form, place an unbound Text Box with the following properties:
  Visible = Yes
  Back Style = Transparent
  Back Color = -2147483633
  Special Effect = Flat
  Border Style = Transparent
  Default Value = " "
  Validation Rule = WheelSpin()=False
'This setting is removed  Validation Text = You can't change record using your mouse wheel!
  Enabled = Yes
  Locked = No
  Name = UnboundTextBox

Step 2.
Then for your Form Properties set this:
  On Mouse Wheel = [Event Procedure]
  On Error = [Event Procedure]

Step 3.
Place the following code behind your form:

CODE


'Global declarations should be here before the code

'This enum is for clarifying the code below.

Private Enum wsTrigger
   MyWheel = 1
   NotTheWheel = 2
End Enum

Private mWheel As Boolean
Private ValidationTrigger As wsTrigger

'End of global declarations


Private Function WheelSpin() As Integer
   WheelSpin = mWheel
   Select Case ValidationTrigger
      Case NotTheWheel
         mWheel = False
   End Select
End Function

Private Sub
Form_Error(DataErr As Integer, Response As Integer)
   If Screen.ActiveControl.Name = "UnboundTextBox" Then
      Response = acDataErrContinue
   End If
End Sub

Private Sub
Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
On Error GoTo Sub_Err
   mWheel = True
   ValidationTrigger = MyWheel
   Me.UnboundTextBox.SetFocus
   Me.UnboundTextBox.TEXT = " "
Sub_Exit:
   ValidationTrigger = NotTheWheel
   Exit Sub
Sub_Err:
   Resume Sub_Exit
End Sub

Thats it!

Have fun
/jollygood

Back to Microsoft: Access Forms FAQ Index
Back to Microsoft: Access Forms Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close