473,382 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

setfocus with a keypress

So I want to go to the top of the form without using the mouse to click on the first textbox.
I understand the keydown and keypress events a little, but from what I've read they are associated with the entire keyboard or any key pressed.

How do I single out one key set to do the job; say the Ctrl + t key combination. If I can understand that then I can also "bind" another key to go to the next fresh form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2. Catch the key;
  3. if the key is "";
  4. then !FORMS!SHOPORDER!textbox1.setfocus;
  5. else do nothing;
  6. End Sub
Or instead of focusing on all keyboard "traffic" I could only watch one or two keys or combinations of them.

Let me know what you guys think would be best.

I appreciate your help,
James
Sep 7 '07 #1
6 4921
ADezii
8,834 Expert 8TB
So I want to go to the top of the form without using the mouse to click on the first textbox.
I understand the keydown and keypress events a little, but from what I've read they are associated with the entire keyboard or any key pressed.

How do I single out one key set to do the job; say the Ctrl + t key combination. If I can understand that then I can also "bind" another key to go to the next fresh form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2. Catch the key;
  3. if the key is "";
  4. then !FORMS!SHOPORDER!textbox1.setfocus;
  5. else do nothing;
  6. End Sub
Or instead of focusing on all keyboard "traffic" I could only watch one or two keys or combinations of them.

Let me know what you guys think would be best.

I appreciate your help,
James
First of all, you're in the wrong Event. To check for a CTRL+T key combination in a Text Box, place the following code in the KeyDown() Event of the Text Box:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   Const conLetterT As Integer = 84
  3.   If (Shift And acCtrlMask) And (KeyCode = conLetterT) Then
  4.     MsgBox "Ctrl and T Pressed!"
  5.   End If
  6. End Sub
Sep 8 '07 #2
Scott Price
1,384 Expert 1GB
Ignore me, just subscribing...

Regards,
Scott
Sep 8 '07 #3
This would work well in a more simple form but this form contains over 100 textboxes. This form is mostly for data entry so the ability to jump around the form with out using a mouse would be great. I need the event to happen inside an object that always has focus. I there an object like that? I thought of using the form as the object for the event but you must first click into the side bar to get that to work. The detail or back ground does not accept key press events.

I guess I could put the procedure into every object in the form but I'm sure their is another way.

I'll research it. Let me know if you guys find a better way to do this.

THanks,
James
Sep 13 '07 #4
Scott Price
1,384 Expert 1GB
Have a look at this post: http://www.thescripts.com/forum/thread705938.html

A brief resumen: KeyPreview property of form to True, use Select case in the KeyDown event to capture your keyboard combinations and navigate to the desired field.

Regards,
Scott
Sep 13 '07 #5
ADezii
8,834 Expert 8TB
This would work well in a more simple form but this form contains over 100 textboxes. This form is mostly for data entry so the ability to jump around the form with out using a mouse would be great. I need the event to happen inside an object that always has focus. I there an object like that? I thought of using the form as the object for the event but you must first click into the side bar to get that to work. The detail or back ground does not accept key press events.

I guess I could put the procedure into every object in the form but I'm sure their is another way.

I'll research it. Let me know if you guys find a better way to do this.

THanks,
James
If you want a Keystroke or Keystrokes to be recognized by the Form itself, and not for any specific Controls contained within the Form, Scott Price gave you the answer.
Sep 13 '07 #6
Works great. Thanks-a-million!
Sep 20 '07 #7

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

Similar topics

3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
2
by: rege | last post by:
Hi, I have two applications developed in C# say A and B. When user presses key "L" with applicaition A active , it causes a keypress event which causes application B to run. Application A then...
1
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled...
4
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1....
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
3
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I...
4
by: AA Arens | last post by:
I use SetFocus to jump from one field to another. That works fine. But one of the focussed fields has default text and this text is selected and the cursor is on the left of it. How to have the...
5
agroover
by: agroover | last post by:
I can't seem to figure out how to get rid of the errors. I recieve the following error when I leave the Grade.SetFocus in my code... Microsoft Access can't move the focus to the control Grade ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.