|
-
May 1st, 2000, 12:30 AM
#1
If I set Menu on a Form, I can also set a short cut for it, like Ctrl-S for Save, however, can I create a short cut key, like Ctrl-S to call the save routine of the document, but this "Save" item isn't exist in the Menu Bar?
-
May 1st, 2000, 01:44 AM
#2
Addicted Member
If I understand your question correctly, yes.
You would setup a keypreview in the form and trap the control-s key to run your save procedure. Example:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
DIM ControlDown
ControlDown = (Shift And vbCtrlMask) > 0
If ControlDown Then
Select Case KeyCode
Case Is = S
'<call your save procedure here!>
End Select
End If
End Sub
-
May 1st, 2000, 01:45 AM
#3
Addicted Member
oops
That the line that says..
Case Is = S
to
Case is = vbKeyS
Thai
-
May 1st, 2000, 01:50 AM
#4
Yes, you can.
Use the Form_KeyDown event to "capture" the key-combination pressed. If applicable, you could also use a different object's KeyDown event.
Example:
Private Sub (KeyCode As Integer, Shift As Integer)
If (Shift And 3) = 2 And KeyCode = vbKeyS Then
' Code to save here, or call DoSave() or whatever
End If
End Sub
This code will catch the CTRL-S combination on the current form.
If you want multiple key-combinations, use a select case statement:
Private Sub (KeyCode As Integer, Shift As Integer)
If (Shift And 3) = 2 ' CTRL is down
Select Case KeyCode
Case vbKeyS
'Code for CTRL-s
Case vbKeyA
' Code for CTRL-a
End Select
End If
End Sub
Hope this helps.
Imar
-
May 1st, 2000, 01:53 AM
#5
Which is about the same as Thai wrote. Sorry Thai, hadn't seen your post yet.
Imar
-
May 1st, 2000, 01:59 AM
#6
Addicted Member
-
May 1st, 2000, 09:10 AM
#7
Thank Thai and Imar, I am tried your method, but I found that it is only what if I don't have any control that will got focus, e.g. If I have a text box on it, then the text box will got the focus so the key down event of the form will not fired. i.e. I need to write code for each object's key down, it will be difficult to maintain when I have many object on it. So I am now try to looking for another method that work no matter how many control on it, just like the Menu bar, it work no matter which control is got focus.
-
May 1st, 2000, 11:27 AM
#8
Addicted Member
do this..
set your keypreview on the form to TRUE and the form will look at any keydown event FIRST, voila.
Thai
-
May 1st, 2000, 11:49 AM
#9
Thai, that is what I want, Thank!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|