Solved

Assign hotkey to textbox for setfocus

Posted on 2001-07-16
6
247 Views
Last Modified: 2006-11-17
I design a form and there are different labels and textbox. I want to go on specific textbox by pressing Alt+F key from keyboard. How it is possible ?

Saleem
0
Comment
Question by:pak_slm
6 Comments
 
LVL 11

Expert Comment

by:Otana
Comment Utility
a simple way is to create a command button out of sight, with a shortcut Alt+F, and then in the onclick event set:

text1.setfocus
0
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 25 total points
Comment Utility
On your main form set KeyPreview = True

In your KeyDown code on the main form

Place the following

Dim AltDown
AltDown = (Shift And vbAltMask) > 0

If KeyCode = vbKeyF Then
  If AltDown Then TextBox1.SetFocus
End If
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
If you have a label describing the textbox, you can set the hotkey in the label's caption using the & character as normal. In order for this to work, you must ensure that the tab order (specified by the tabindex property for each control) places the label one place lower than the corresponding textbox:

Label1    TabIndex = 0
Text1     TabIndex = 1

Label1.Caption = "&Hello There"

In this scenario pressing Alt+H would set focus to the text box as the subsequent control in the tab order.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:pak_slm
Comment Utility
I prefer your answer because it is code based.
Thanks.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Your welcome
0
 
LVL 1

Author Comment

by:pak_slm
Comment Utility
If i place a button or through label caption then i feel problem because i want more then one hotkey.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now