Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control with Mouse Click Event - Is it possible? 1

Status
Not open for further replies.

ssecca

Programmer
Feb 13, 2002
219
US
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.

Is there a way do accomplish this?

Thanks Much
 
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

PaulF
 
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.

Hope this helps.


[pc2]
 
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

Thanks Again mp9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top