Mike Express
01-18-2020, 12:47 PM
I have a Word .dotm test form through which I Tab to successive form fields and fill them out before Tabbing to the next field. I have VBA code I execute on Exit of each field to check tolerances of the numbers entered in each field. However, I want to be able to stop filling out the form and go to some other place in the document by scrolling somewhere far away and clicking there. For example, I might wish to only do a partial test then go back to the top of the document where I mark the test pass or fail. However, if I click far away, I'm dragged back to the last field where I left off to display that I failed the tolerance of that field because I left the procedure before finishing all the fields of the test. 
So I'd like to detect when I go to some far away field by using the mouse button verses when I use the Tab button to go to the the next field in the usual procedure. I think the only way to detect a premature departure of the normal sequence is to detect a LEFT mouse button by using the MouseDown function in VBA. I'm hoping that this function will execute before I run macro on exit of the field where I left off before I clicked far away. Then the MouseDown code can set a variable that disables the Out of Tolerance message box from displaying. Then I can use the Mouse to prematurely exit the testing procedure and go anywhere I like without being dragged back to the last field not yet filled out. 
But I don't know the details of using the MouseDown function. Can anyone here offer any help? I'm not sure I need to create Class modules and event_handlers, etc. Any help is appreciated. Thank you.
Mike Express
01-19-2020, 11:24 AM
So one question I have is does MouseDown work anywhere in a document, or just in certain types of form fields?
I could find no help for Mouse Events in Word XP Help
MS Forms (Legacy) does have mouse Events.
Here's the Mouse Events Help page
MouseDown, MouseUp Events                             
 Occur when the user clicks a mouse button. MouseDown occurs when the  user presses the mouse button; MouseUp occurs when the user releases the mouse  button.
 Syntax
 For MultiPage, TabStrip
Private Sub  object_MouseDown( index As Long, ByVal  Button As fmButton, ByVal Shift As  fmShiftState, ByVal X As Single, ByVal Y  As Single)
Private Sub object_MouseUp(  index As Long, ByVal Button As fmButton,  ByVal Shift As fmShiftState, ByVal X As  Single, ByVal Y As Single)
 For other controls
Private Sub  object_MouseDown( ByVal Button As fmButton,  ByVal Shift As fmShiftState, ByVal X As  Single, ByVal Y As Single)
Private Sub  object_MouseUp( ByVal Button As fmButton,  ByVal Shift As fmShiftState, ByVal X As  Single, ByVal Y As Single)
 The MouseDown and MouseUp event syntaxes have these  parts:
 
  
 Part
 Description
 
 object
 Required. A valid object.
 
 index
 Required. The index of the page or tab in a  MultiPage or TabStrip with the specified event.
 
 Button
 Required. An integer value that identifies which mouse  button caused the event.
 
 Shift
 Required. The state of SHIFT, CTRL, and  ALT. 
 
 X, Y
 Required. The horizontal or vertical position, in  points, from the left or top edge of the form, Frame, or  Page.
Settings
 The settings for Button are:
 
  
 Constant
 Value
 Description
 
 fmButtonLeft
 1
 The left button was pressed.
 
 fmButtonRight
 2
 The right button was pressed.
 
 fmButtonMiddle
 4
 The middle button was  pressed.
The settings for Shift are:
 
  
 Value
 Description
 
 1
 SHIFT was pressed.
 
 2
 CTRL was pressed.
 
 3
 SHIFT and CTRL were pressed.
 
 4
 ALT was pressed.
 
 5
 ALT and SHIFT were pressed.
 
 6
 ALT and CTRL were pressed.
 
 7
 ALT, SHIFT, and CTRL were  pressed.
You can identify individual keyboard modifiers by using the following  constants:
 
  
 Constant
 Value
 Description
 
 fmShiftMask
 1
 Mask to detect SHIFT.
 
 fmCtrlMask
 2
 Mask to detect CTRL.
 
 fmAltMask
 4
 Mask to detect ALT.
Remarks
 For a MultiPage, the MouseDown event occurs when the user  presses a mouse button over the control.
 For a TabStrip, the index argument identifies the tab where  the user clicked. An index of –1 indicates the user did not click a tab. For  example, if there are no tabs in the upper right corner of the control, clicking  in the upper right corner sets the index to –1.
 For a form, the user can generate MouseDown and MouseUp events by  pressing and releasing a mouse button in a blank area, record selector, or  scroll bar on the form.
 The sequence of mouse-related events is:  
 MouseDown
 MouseUp
 Click
 DblClick
 MouseUp
 MouseDown or MouseUp event procedures specify actions that occur when  a mouse button is pressed or released. MouseDown and MouseUp events enable you  to distinguish between the left, right, and middle mouse buttons. You can also  write code for mouse-keyboard combinations that use the SHIFT, CTRL, and ALT  keyboard modifiers.
 If a mouse button is pressed while the pointer is over a form or  control, that object "captures" the mouse and receives all mouse events up to  and including the last MouseUp event. This implies that the X, Y  mouse-pointer coordinates returned by a mouse event may not always be within the  boundaries of the object that receives them.
 If mouse buttons are pressed in succession, the object that captures  the mouse receives all successive mouse events until all buttons are  released.
 Use the Shift argument to identify the state of SHIFT, CTRL,  and ALT when the MouseDown or MouseUp event occurred. For example, if both CTRL  and ALT are pressed, the value of Shift is 6.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.