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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Click event but if shift key pressed do something else 1

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I have a button say cmdThis.

Which runs procedure one.

i.e.

I also have created a cmdThis_KeyDown

which detect if the shift key is pressed whilst the cmdThis button is selected.

What I want is that if the shift key is pressed it runs procedure 2 without procedure 1. However if it doesnt it runs procedure 1 only.

Any clues?
 
If you really want to do this, then rather than hooking the Click event, you should try the MouseUp/MouseDown events. If MouseUp occurs within a specific time of the MouseDown then effectively a click has occured and then you can check the MouseUp event parameters for the state of the Shift Key.

Hope this helps.
 
My point is that expecting the user to know when to use shift and when to just click is simply asking for trouble.

If running the wrong procedure has no consequence then fine, but if either of them do something that matters then you can expect problems.

You can do things like this:

Option Compare Database
Option Explicit
Dim flag As Boolean
Private Sub Command0_Click()

If flag = True Then
Procedure1
Else
End If


End Sub

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

If (Shift And acShiftMask) Then
Procedure2
flag = False
Else
flag = True
End If
End Sub
 

May be a second button to run procedure 2 and not procedure 1 would be much simplier and clear for any unexpirienced user to learn and get it right every time! I would also add a tool tip for every button and a confirmation msgbox. They [red]never[/red] read the manual but they love calling help desk!
 
Just so everyone knows procedure 1 is to basically send a report to the printer and create a snap shot of it to save to disk etc.

The reason y i want the shift key thing is because they rarely need to edit these letters. hence don't want to hog up the form with buttons etc. On the occasional instance when the letter may need to be edited (hence output the file to rtf and open that up, rather than the earlier) they would quite simply select the option to print whilst holding down shift so hey can edit the doc.

The database is quite a huge one (for access any way) and works quite well how I have done things. There are a hundred or so letters on there. and some quite complex routines for the business. I'm sure holding down shift if they need to edit won't be too difficult for a user, as they have coped quite well with more difficult processes in the past.

Sorry if this entry sounds a bit stroppy but it is not intended in that way.

Thank you all for responding to my thread.

X
 
How about this?
I have a hidden textbox on the form that stores the keycode. the compare the keycode onclick of the command button
Code:
Option Compare Database
Dim x As Integer
'------------------------------
Private Sub Command2_Click()
If x = 16 Then
MsgBox "You pressed shift key"
Else
MsgBox "you pressed another key"
End If
End Sub
'-------------------------------
Private Sub Form_KeyDown(keycode As Integer, Shift As Integer)
'set form keypreview =true
x = keycode
Me.Text0 = x
End Sub
'--------------------------------

________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
Hi Neemi,

Here's a simple alternative to holding down keys and storing/evaluating key codes and such-like:
Code:
Private Sub Command0_Click:

If MsgBox("Do you need to edit this letter?",vbYesNo+vbDefaultButton2+vbQuestion) = vbNo Then
    'Do your print and save code here
Else
    'Do your export and open code here
End If

End Sub

[pc2]
 
well this is what I thought and suggested to do but the boss has asked to do it as I posted in the thread!

Thanks anyway.

The last suggestion does make sense though.. It is what I naturally thought to do..

but hey..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top