Link to home
Start Free TrialLog in
Avatar of naqayya
naqayya

asked on

KeyCode combination

I use the following code to run cmdGoToNext_Click when F10 is pressed:

-----------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If KeyCode = vbKeyF10 And cmdGoToNext.Visible = True Then
        cmdGoToNext_Click
    End If
   
End Sub
------------------------------------------------------

What should the code be to use Ctrl & Right Arrow together instead of F10?

Thanks.
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
   If (KeyCode = 39 and shift = 2) And cmdGoToNext.Visible = True Then
       cmdGoToNext_Click
   End If
   
End Sub
more properly it is

If KeyCode = vbKeyRight And CBool(Shift And vbCtrlMask) Then
   
    MsgBox "YES"
   
End If
Avatar of naqayya
naqayya

ASKER

deighton:

Both your solutions don't seem to work. When I use the first solution I get an error message, and the second just does an ordinary move right (to next field).

My code is:

-----------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If (KeyCode = vbKeyLeft And CBool(Shift And vbCtrlMask)) And (cmdGoToNext.Visible = True) Then
        cmdGoToNext_Click
   
    End If
   
End Sub


Private Sub cmdGoToNext_Click()

    Check_Allocations
   
    If StopCodeExecution = True Then
        StopCodeExecution = False
        Exit Sub
    Else
        DoCmd.GoToRecord acDataForm, "frmDonations", acNext
    End If

End Sub
______________________________________________________

Can you help? Thanks.
sorry dude, I guess that the arrow key still carries out its function regardless.  I don't know how to stop that behaviour.

Feel free to delete the question and repost it if you want
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naqayya

ASKER

deighton: Thanks for that.

Jim: It works! Thanks again. BTW, can use a boolean type for intCtrlDown?
<<BTW, can use a boolean type for intCtrlDown? >>

 Not sure.  I've never tried it that way.  True/false in Access is an integer type (-1/0).  I've generally stayed away from the boolean type and implicit logic checks because of past bugs.

Jim.