I wish to extend the functionality of the "click event" from a control on a bound Access(XP) form. I want to take special action when a user clicks a control while holding the <ctrl> key down.
You can create a Form Level Boolean variable that you can set to TRUE when the Control Key is Depressed (using the Form's KeyDown Event) and reset it back to False when when released (using the Form's KeyUp Event) then check this value when the command button is clicked.. besure to set the Form's KeyPreview to True
Option Compare Database
Option Explicit
Dim blnCtl As Boolean
Private Sub Command0_Click()
If blnCtl = True Then
MsgBox "Control Key Depressed"
Else
MsgBox "Control Key Is Not Depressed"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyControl Then
blnCtl = True
Else
blnCtl = False
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
blnCtl = False
End Sub
Use the controls' OnMouseDown event. Say your control is called MyControl1, then the event handler would be something like:
Code:
Private Sub MyControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Shift=2 Then
'Ctrl key was held down when mouse was clicked
'Do relevant code here
End If
End Sub
Likewise a value of 1 for Shift, indicates the Shift key was down, 3 that both Shift and Ctrl were down, 4 that Alt was down, and so on.
Thank You mp9, I never realized what the shift variable was used for. I guess I never needed it before.
For others looking on
"SHIFT" =
1 when the <Shift> key is pressed while clicking
2 when the <ctrl> key is pressed while clicking
4 when the <alt> key is pressed while clicking
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.