I want to create two keyboard shortcuts in Access 2007.
If one keyboard combination is pressed, the word "Unique" is input into a column value.
If another keyboard combination is pressed, the word "Duplicate" in input into a column value.
This is fairly easy in Excel, I am hoping to do the same in Access. I would just record the action in a macro. But it appears that access has predefined actions for Macros.
Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
'Here are the 7 combinations of the Shift argument ...
'from which you can trap any combination of Shift, Control and Alt ...
'in either the Form_KeyDown and Form_KeyUp events.
'Also ... be SURE you have Key Preview set to Yes on the Event property sheet for the Form.
'Shift Argument for the 7 combinations of Shift, Ctrl and Alt keys:
'0 None
'1 Shift Key
'2 Ctrl Key
'3 Shift + Ctrl Keys
'4 Alt Key
'5 Shift + Alt Keys
'6 Ctrl + Alt Keys
'7 Shift + Ctrl + Alt Keys
'----------------------------------------
If Shift = 4 Then
If KeyCode = vbKeyU Then Me.txtBox = "Unique"
End If
Alt+U will enter Unique in the text box,
Alt+D will enter Duplicate in the text box.
You can actually many different shortcuts using a combination of Alt, Shift & Control ... simply by changing the Shift number in the If/Then statements.
mx
Microsoft Access
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)
'Here are the 7 combinations of the Shift argument ...
'from which you can trap any combination of Shift, Control and Alt ...
'in either the Form_KeyDown and Form_KeyUp events.
'Also ... be SURE you have Key Preview set to Yes on the Event property sheet for the Form.
'Shift Argument for the 7 combinations of Shift, Ctrl and Alt keys:
'0 None
'1 Shift Key
'2 Ctrl Key
'3 Shift + Ctrl Keys
'4 Alt Key
'5 Shift + Alt Keys
'6 Ctrl + Alt Keys
'7 Shift + Ctrl + Alt Keys
'-------------------------
If Shift = 4 Then
If KeyCode = vbKeyU Then Me.txtBox = "Unique"
End If
End Sub
mx