Hi All,
This is really basic but I'm having trouble finding a straight forward way to do this. I have an Access application where the for is in spreadsheet mode. When a user leaves a control there is a series of calculations and the parent and child forms are refreshed. The cursor goes back up to the first control in the first record after refreshed and I bring it back to the original record using a bookmark.
My problem is that I need to determine where to put the cursor depending on the keystroke pressed. For example, if the user presses the down arrow key, I want the key to go to a certain control. If the user presses the tab key I want it to go to the next control in the record.
Can anyone help. Here is an example of the current code where I need to build this in.
Private Sub Labor_hours_LostFocus()
Dim varBookmark As Variant
varBookmark = Me.Bookmark
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Select Case Me.[Record Type]
Case 3
DoCmd.OpenQuery "Update Task Record-Template", , acEdit
DoCmd.OpenQuery "Delete calc record", , acEdit
DoCmd.OpenQuery "calculate template tasks 2-category", , acEdit
DoCmd.OpenQuery "Update Category Record-template", , acEdit
DoCmd.OpenQuery "Delete calc record", , acEdit
DoCmd.OpenQuery "calculate template tasks 2-phase", , acEdit
DoCmd.OpenQuery "Update Phase Record-template", , acEdit
Me.Requery
Me.Bookmark = varBookmark
If Forms![main switchboard]![Form Status] = True Then
DoCmd.GoToControl "Labor UM" 'GOTO THE NEXT FIELD
Else
Forms![main switchboard]![Form Status].Value = True
End If
Case Else
'do nothing
End Select
End Sub
Thanks Much!
3 9184
Hi All,
This is really basic but I'm having trouble finding a straight forward way to do this. I have an Access application where the for is in spreadsheet mode. When a user leaves a control there is a series of calculations and the parent and child forms are refreshed. The cursor goes back up to the first control in the first record after refreshed and I bring it back to the original record using a bookmark.
My problem is that I need to determine where to put the cursor depending on the keystroke pressed. For example, if the user presses the down arrow key, I want the key to go to a certain control. If the user presses the tab key I want it to go to the next control in the record.
Can anyone help. Here is an example of the current code where I need to build this in. - Private Sub Labor_hours_LostFocus()
-
-
Dim varBookmark As Variant
-
-
varBookmark = Me.Bookmark
-
-
DoCmd.SetWarnings False
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
-
-
Select Case Me.[Record Type]
-
-
Case 3
-
DoCmd.OpenQuery "Update Task Record-Template", , acEdit
-
DoCmd.OpenQuery "Delete calc record", , acEdit
-
DoCmd.OpenQuery "calculate template tasks 2-category", , acEdit
-
DoCmd.OpenQuery "Update Category Record-template", , acEdit
-
-
DoCmd.OpenQuery "Delete calc record", , acEdit
-
DoCmd.OpenQuery "calculate template tasks 2-phase", , acEdit
-
DoCmd.OpenQuery "Update Phase Record-template", , acEdit
-
-
-
Me.Requery
-
-
Me.Bookmark = varBookmark
-
-
If Forms![main switchboard]![Form Status] = True Then
-
DoCmd.GoToControl "Labor UM" 'GOTO THE NEXT FIELD
-
Else
-
Forms![main switchboard]![Form Status].Value = True
-
End If
-
-
Case Else
-
'do nothing
-
-
-
End Select
-
-
End Sub
Thanks Much!
It will probably be more visual than basic by the time you get done :-) Here's a link to a thread with a similar question: http://www.thescripts.com/forum/thread704885.html
The constants that you will need to use are: vbKeyTab for the tab key, and 40 for the down arrow key... Here's another posting with some additional information: http://www.thescripts.com/forum/thread658216.html
Regards,
Scott
Hi All,
This is really basic but I'm having trouble finding a straight forward way to do this. I have an Access application where the for is in spreadsheet mode. When a user leaves a control there is a series of calculations and the parent and child forms are refreshed. The cursor goes back up to the first control in the first record after refreshed and I bring it back to the original record using a bookmark.
My problem is that I need to determine where to put the cursor depending on the keystroke pressed. For example, if the user presses the down arrow key, I want the key to go to a certain control. If the user presses the tab key I want it to go to the next control in the record.
Can anyone help. Here is an example of the current code where I need to build this in.
Private Sub Labor_hours_LostFocus()
Dim varBookmark As Variant
varBookmark = Me.Bookmark
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Select Case Me.[Record Type]
Case 3
DoCmd.OpenQuery "Update Task Record-Template", , acEdit
DoCmd.OpenQuery "Delete calc record", , acEdit
DoCmd.OpenQuery "calculate template tasks 2-category", , acEdit
DoCmd.OpenQuery "Update Category Record-template", , acEdit
DoCmd.OpenQuery "Delete calc record", , acEdit
DoCmd.OpenQuery "calculate template tasks 2-phase", , acEdit
DoCmd.OpenQuery "Update Phase Record-template", , acEdit
Me.Requery
Me.Bookmark = varBookmark
If Forms![main switchboard]![Form Status] = True Then
DoCmd.GoToControl "Labor UM" 'GOTO THE NEXT FIELD
Else
Forms![main switchboard]![Form Status].Value = True
End If
Case Else
'do nothing
End Select
End Sub
Thanks Much!
To accomplish what you are requesting, you must capture the User's Keystrokes at the Form Level. To do this:- Set the KeyPreview Property of the Form to Yes.
- Place similar code in the Form's KeyDown() Event. The sample code snippet will capture most of the Navigation Keys:
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
Const vbKeyEnter = 13
-
-
Select Case KeyCode
-
Case vbKeyHome
-
'Home Key presseed
-
Case vbKeyEnd
-
'End Key pressed
-
Case vbKeyPageUp
-
'etc.
-
Case vbKeyPageDown
-
'etc.
-
Case vbKeyUp
-
'etc.
-
Case vbKeyDown
-
'etc.
-
Case vbKeyLeft
-
'etc.
-
Case vbKeyRight
-
'etc.
-
Case vbKeyTab
-
'etc.
-
Case vbKeyEnter
-
'etc.
-
End Select
-
End Sub
I have just been directed to work on another part of the program first so I won't get to this for a couple of days but it looks like this code is exactly what I'm looking for. I will respond as to how it works then. This is a tremendous help and this forum is a great resource!
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
1 post
views
Thread by Anita C |
last post: by
|
reply
views
Thread by hoenes1 |
last post: by
|
5 posts
views
Thread by Bill |
last post: by
|
4 posts
views
Thread by jeremiah johnson |
last post: by
|
8 posts
views
Thread by rdemyan via AccessMonster.com |
last post: by
|
3 posts
views
Thread by =?Utf-8?B?cGFucGF3ZWw=?= |
last post: by
|
8 posts
views
Thread by Johannes Meng |
last post: by
| | | | | | | | | | | | |