1

I have a button on a form in ms-access where I have both a "On Click" and "on Dbl Click" events filled. I am running into the problem that the single click event works but the double click will not unless on the second click, I keep holding it down and drag the mouse off the button before I release it. What this button does is it fills a textbox with certain text depending on the 2 different clicks. How is it I can fix this double click issue? The code for the buttons is below. Note that Task_ID_AfterUpdate() also fills in text fields according to what the Me.Task_ID is by looking it up in a Query.

'single click
Private Sub getBtn_Click()
    btnUpdateHelper (1162)
End Sub

'double click
Private Sub getBtn_DblClick(cancel As Integer)
    btnUpdateHelper (1449)
End Sub

Private Sub btnUpdateHelper(Task As Variant)
    'helper method for buttons, only pass task id
    'Me.Task_ID is a textfield
    Me.Task_ID = Task
    Task_ID_AfterUpdate
End Sub

Private Sub Task_ID_AfterUpdate()
    Dim taskIdNum As String
    taskIdNum = Me.Task_ID
    'updates all fields to display the selected task
    Me.Area = DLookup("Area", "Query", "TaskID=" & taskIdNum)
    Me.Activity = DLookup("Activity", "Query", "TaskID=" & taskIdNum)
    Me.Description = DLookup("Description", "Query", "TaskID=" & taskIdNum)
    Me.Comments = DLookup("Comments", "Query", "TaskID=" & taskIdNum)
    Me.Task_Group = DLookup("[Task Group]", "Query", "TaskID=" & taskIdNum)
    Me.Mul = DLookup("Mul", "Query", "TaskID=" & taskIdNum)
    Me.Time = DLookup("Time", "Query", "TaskID=" & taskIdNum)
End Sub
2
  • 1
    That is a very strange UI design. May I suggest to use either right-click or Shift+click for the alternate function? Use the _MouseDown event to catch these. Commented May 24, 2017 at 16:04
  • @Andre Thank You!! If you submit that as an answer, I will accept it Commented May 24, 2017 at 16:17

1 Answer 1

1

Putting Click and DblClick events on a button is IMO a rather confusing UI design. Better is to use either right-click or Shift+click (or Alt or Ctrl) for alternate functions.

The Click event doesn't catch these modifiers, only MouseDown and MouseUp. It feels most natural if the actions are put in the MouseUp event procedure, e.g.

Private Sub cmdMultiClick_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim SelectedFunction As String

    If Button = acLeftButton Then
        If (Shift And acShiftMask) Then
            SelectedFunction = "Shift-Left click!"
        Else
            SelectedFunction = "Left click!"
        End If
    ElseIf Button = acRightButton Then
        SelectedFunction = "Right click!"
        ' Cancel the default right-click behavior (open context menu)
        DoCmd.CancelEvent
    End If

    MsgBox SelectedFunction, vbInformation

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.