473,692 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine last key pressed by user

7 New Member
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_Los tFocus()

Dim varBookmark As Variant

varBookmark = Me.Bookmark

DoCmd.SetWarnin gs False

DoCmd.DoMenuIte m 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.GoToContr ol "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!
Sep 10 '07 #1
3 9515
Scott Price
1,384 Recognized Expert Top Contributor
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Labor_hours_LostFocus()
  2.  
  3. Dim varBookmark As Variant
  4.  
  5. varBookmark = Me.Bookmark
  6.  
  7. DoCmd.SetWarnings False
  8.  
  9. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  10.  
  11. Select Case Me.[Record Type]
  12.  
  13. Case 3
  14. DoCmd.OpenQuery "Update Task Record-Template", , acEdit
  15. DoCmd.OpenQuery "Delete calc record", , acEdit
  16. DoCmd.OpenQuery "calculate template tasks 2-category", , acEdit
  17. DoCmd.OpenQuery "Update Category Record-template", , acEdit
  18.  
  19. DoCmd.OpenQuery "Delete calc record", , acEdit
  20. DoCmd.OpenQuery "calculate template tasks 2-phase", , acEdit
  21. DoCmd.OpenQuery "Update Phase Record-template", , acEdit
  22.  
  23.  
  24. Me.Requery
  25.  
  26. Me.Bookmark = varBookmark
  27.  
  28. If Forms![main switchboard]![Form Status] = True Then
  29. DoCmd.GoToControl "Labor UM"   'GOTO THE NEXT FIELD
  30. Else
  31. Forms![main switchboard]![Form Status].Value = True
  32. End If
  33.  
  34. Case Else
  35. 'do nothing
  36.  
  37.  
  38. End Select
  39.  
  40. 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
Sep 10 '07 #2
ADezii
8,834 Recognized Expert Expert
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_Los tFocus()

Dim varBookmark As Variant

varBookmark = Me.Bookmark

DoCmd.SetWarnin gs False

DoCmd.DoMenuIte m 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.GoToContr ol "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:
  1. Set the KeyPreview Property of the Form to Yes.
  2. Place similar code in the Form's KeyDown() Event. The sample code snippet will capture most of the Navigation Keys:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. Const vbKeyEnter = 13
    3.  
    4.   Select Case KeyCode
    5.     Case vbKeyHome
    6.       'Home Key presseed
    7.     Case vbKeyEnd
    8.       'End Key pressed
    9.     Case vbKeyPageUp
    10.       'etc.
    11.     Case vbKeyPageDown
    12.       'etc.
    13.     Case vbKeyUp
    14.       'etc.
    15.     Case vbKeyDown
    16.       'etc.
    17.     Case vbKeyLeft
    18.       'etc.
    19.     Case vbKeyRight
    20.       'etc.
    21.     Case vbKeyTab
    22.       'etc.
    23.     Case vbKeyEnter
    24.       'etc.
    25.   End Select
    26. End Sub
Sep 11 '07 #3
mmckinnon
7 New Member
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!
Sep 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3006
by: Anita C | last post by:
Hi, How cookies can be used to set and then determine the last page visited by a person browsing a particular website ? Also the page last visited is loaded in an iframe, so the page last visited inside a particular iframe is what really needs to be determined. So when the application starts up the next time, if the last page visited was admin.aspx inside frame IContent, then show admin.aspx in Icontent or else show home.aspx. A code...
0
1114
by: hoenes1 | last post by:
How can I determine whether a download has been cancelled by the client? I'm sending the file from an aspx page in chunks of 4K. When the user presses "Cancel" in his download dialog, the next call of Response.Flush() hangs and resets my Session Object after about a minute. The Response.IsClientConnected property is still true after the user pressed "Cancel". Is there a workaround for this problem? The Code is: // fs --> FileStream //...
5
10513
by: Bill | last post by:
Hello, Could anyone post some simple code or advise me on how I can display the SSN number like *****7890 in a text box, even thought the user entered 1234567890, and the value of the variable would remain the same. Only thing I can think of is, accept the user input load it into a varible, and then just take the last 4 digits of the number and concatenate it to 5 *'s and replace the text box variable with that.... I was hoping there was a...
4
10144
by: jeremiah johnson | last post by:
Hi all. I'm writing a small utility that can move a window from one of my monitors to the other, when a system hotkey is pressed. I want to keep the windowstate (maximized or normal) when the window is moved, but I need to know the windowstate in order to move it properly. I'm using some P/Invoke calls to get the window handles and the window placement, which all works well, but I can't find a way to determine if a window is...
8
1929
by: rdemyan via AccessMonster.com | last post by:
Anyone have any ideas on how to determine when the back-end file (containing only tables) has been updated with new data. The date/time of the file won't work because it gets updated to the current date/time when the back-end file is compacted. I'm just looking for an easy way to determine when there has been a change to data in any table in the back-end file. Maybe something is updated in one of the system tables??
3
17826
by: =?Utf-8?B?cGFucGF3ZWw=?= | last post by:
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or '0'-'9' range? I really don't like to write switch with every Keys.A, Keys.B, etc key listed Paul
8
3466
by: Johannes Meng | last post by:
Good day, I'm experimenting with unbuffered input at the moment. To get input I basically use cin.get(). My problem are control sequences preceeded by an ESC character (i.e. up, down, f-keys et cetera). They basically look like this: <ESC><EXCODE><CODE>, where EXCODE is a number describing the type of key pressed and CODE is the actual key. I want to be able to decide whether ESC or such a control key was pressed. Now if I do it like...
6
2868
by: JWest46088 | last post by:
I'm trying to figure out how to read if a key was pressed by the user. For example, a line from a file is displayed and the user is prompted to hit any key to see the next line in the file. I've tried getc(STDIN) with no luck. Maybe I didn't do it right; I don't know. Any suggestions on how I can do this?
1
5005
by: AdamOnAccess | last post by:
I'm in Access 2007. I built a feature that to saves the current list in a sub form to a separate table. It works like this: After entering a list of words in the subform, the user can choose to push a button, and a dialog box appears. The user enters a name into the dialog box to identify the list for later use, presses OK and the list is saved. In the code, I'm using DoCmd.RunSql on the data in the table, so all the data in the sub form...
0
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7639
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5822
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2983
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.