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

Question about OnDownKey event? URGENT 2

Status
Not open for further replies.

quest4

Technical User
Aug 27, 2001
735
US
Good morning everyone. Can someone please tell me how to code: When CTRL-b is pressed do a procedure. Thanks you to anyone who helps, I really hate dead lines.
 
I think this will work for a single form.

Paste this into the Declarations section of your form:
Dim booControlKeyPressed As Boolean

Paste this into the On Load event of your form:
booControlKeyPressed = False

Paste this into the On Key Down event of your form:
If KeyCode = vbKeyControl Then
booControlKeyPressed = True
End If
If booControlKeyPressed = True Then
If KeyCode = vbKeyB Then
MsgBox "Ctrl + B was pressed!"
gControlKeyPressed = False
ElseIf KeyCode = vbKeyC Then
MsgBox "Ctrl + C was pressed!"
gControlKeyPressed = False
End If
End If
If KeyCode <> vbKeyControl Then
booControlKeyPressed = False
End If

Paste this into the On Key Up event of your form:
If KeyCode = vbKeyControl Then
booControlKeyPressed = False
End If

You will need to set the Key Preview property of the form to Yes.

Assuming this works, you should easily be able to convert this into a Public Procedure available to all your forms.

Bill
 
Thank you very much Bill. I will try this but I have a 2 line procedure, where would I put this? Also I don't think I need this to be public, it is a subform, which is used in two forms, that is it. Thank you again for the assistance, I do appreciate it.
 
Hi,
may like this:

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)

Dim ControlDDown As Integer
ControlDDown = (KeyCode = vbKeyD And Shift And acCtrlMask) > 0

If ControlDDown = True Then
Call <procedure>
End If

End Sub
 
Hi quest4,

You would replace the example MsgBox &quot;Ctrl + B was pressed!&quot; with your code/procedure.

Bill
 
Bill, what is the declation section of a form? I have heard of it for fuctions, but not forms. Thanks.
 
Hi boriska40,

I think your suggestion is excellent, much better than what I've previously used and suggested to quest4. (quest4, please disregard my suggestion and go with boriska40)

Thanks very much for teaching me something new.

Thanks again and a * for you.

Bill
 
Thank you for the response Boriska40. Does this this go in the form OnKeyDown event? Thank you everyone for all of the assistance.
 
I tried this in the ON KeyDown event and I get a Missing Separator error, can any one tell me where I went wrong?
Hereis the code:
'Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)

Dim ControlDDown As Integer
ControlDDown = (KeyCode = vbKeyD And Shift And acCtrlMask) > 0

If ControlDDown = True Then
Me.PartGroup = Me.PartGroup + 1
ERROR-> Me.ItemNumber = Nz(DMax(&quot;[ItemNumber]&quot;,&quot;stblECN_BOM&quot;,&quot;[PartGroup]&quot; = &quot; & Me!PartGroup)) +1
End If

End Sub
I commented out the orginal in favor of the line Boriska40 gave me, which is correct? Thanks for the assistance.
 
Than you for the assistance boriska40. It turnout out to be an extra &quot;. But it is not increasing the PartGroup by 1, it is like I never touched CTRL-b at all and I even tried pushing it 2 and 3 times and still nothing. Here is what I am using:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim ControlDDown As Integer
ControlDDown = (KeyCode = vbKeyD And Shift And acCtrlMask) > 0

If ControlDDown = True Then
Me.PartGroup = Me.PartGroup + 1
Me.ItemNumber = Nz(DMax(&quot;[ItemNumber]&quot;, &quot;stblECN_BOM&quot;, &quot;[PartGroup] = &quot; & Me!PartGroup), 0) + 1
End If

End Sub
I also tried it with and without the shift key. When this works I am done, I hope. tahnk you so very much for all of the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top