473,566 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using keystroke to select an option from an option group in an Access form

luvgis
12 New Member
I have an Access form to be used for data entry of returned bus surveys. The survey consists of 15 questions and several of the questions will be options groups in the form. For example, question 1 is “When you boarded the bus today, where were you coming from?” The available options are (1) Home, (2) Work, (3) Shopping, ect. I want the data entry person to be able to either select the radio button with the mouse OR be able to tab through hit the appropriate number on the keyboard, (1 for home, 2 for work…) when the first control in the group has focus. I haven’t been able to find any examples of using the On KeyPress event (if that is the right one) in this way. Could someone point me in the right direction?
May 20 '09 #1
4 2339
ADezii
8,834 Recognized Expert Expert
@luvgis
It is not exactly intuitive how this can be done since an Option Group does not have any Key Events, but here is a little trickery that you can try:
  1. Set the KeyPreview Property of the Form = Yes which will allow the Form to process any Keystrokes prior to any Controls contained within the Form.
  2. In the Form's KeyPress() Event, make sure the specific Option Group has the Focus, in this case I'll name it optComingFrom.
  3. Select the appropriate Option in the Option Group if either a 1, 2, or 3 is pressed on the Keyboard.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_KeyPress(KeyAscii As Integer)
    2. If Screen.ActiveControl.Name = "optComingFrom" Then
    3.   Select Case KeyAscii
    4.     Case vbKey1
    5.       Me![optComingFrom] = 1
    6.     Case vbKey2
    7.       Me![optComingFrom] = 2
    8.     Case vbKey3
    9.       Me![optComingFrom] = 3
    10.     Case Else
    11.       'not really concerned
    12.   End Select
    13. End If
    14. End Sub
  4. Expand the concept for additional Option Groups on the Form.
May 20 '09 #2
luvgis
12 New Member
Thank you so much, your directions were perfect.
I kept looking for the "OnKeyPress " property of the Details section of the form when I should of been looking at the properties of the form itself (which by the way for other newbies can be viewed by right clicking in the little square on the upper left-hand corner of the form in design view). I added a "highlight box" to show up when the control group is active so the user would know which question they were on. I want to share the code for anyone else who may be interested...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.  
  3. If Screen.ActiveControl.Name = "Frame_Question1" _
  4. Then
  5.  
  6. 'Highlight the question
  7. Me.HighlightBox_Question1.Visible = True
  8.  
  9. Select Case KeyAscii
  10.     Case vbKey1
  11.       Me!Frame_Question1 = 1
  12.     Case vbKey2
  13.       Me!Frame_Question1 = 2
  14.     Case vbKey3
  15.       Me!Frame_Question1 = 3
  16.     Case vbKey4
  17.       Me!Frame_Question1 = 4
  18.     Case vbKey5
  19.       Me!Frame_Question1 = 5
  20.     Case vbKey6
  21.       Me!Frame_Question1 = 6
  22.     Case vbKey7
  23.       Me!Frame_Question1 = 7
  24.     Case vbKey8
  25.       Me!Frame_Question1 = 8
  26.     Case vbKey9
  27.       Me!Frame_Question1 = 9
  28.     Case vbKey0
  29.       Me!Frame_Question1 = 10
  30.     Case Else
  31.       'not really concerned
  32.   End Select
  33. End If
  34.  
  35. If Screen.ActiveControl.Name <> "Frame_Question1" _
  36. Then
  37.  
  38. 'Remove Highlight
  39. Me.HighlightBox_Question1.Visible = False
  40.  
  41. End If
  42.  
  43. End Sub
May 21 '09 #3
ADezii
8,834 Recognized Expert Expert
Glad it all worked out for you.
May 21 '09 #4
NeoPa
32,564 Recognized Expert Moderator MVP
By placing an ampersand character (&) before the digits in the associated labels, it is possible to press Alt- followed by the associated digit to trigger the button automatically.

This isn't exactly what's requested I know, but it does the benefit of being an inbuilt, available option.
May 24 '09 #5

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

Similar topics

1
3498
by: Dan Williams | last post by:
I have a simple select form element object and want to be able to get it to select whatever the user chooses when they right-click in it. I've managed to use the following code, but on the right-click it displays whatever was previously selected and still highlighted with the left click. Is there a way to get a right click in the select...
10
7632
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how the onchange event isn't called when mouse wheel scrolling between A3 and B1, but it works properly when scrolling between A1 and A2. E.g....
6
2688
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at http://www.lebans.com/DownloadFiles/A2kTooltip.zip So far the classes work perfectly, except that now I need to extend it to support other controls besides...
5
7369
by: Colin Anderson | last post by:
I discovered, with great excitement, this article http://www.davison.uk.net/vb2notes.asp when researching methods for emailing from Access via Notes. Unfortunatly, when I run this I get a Run-time error. When I run it on an XP machine it crashes, but on an NT box it just generates an unknown error, handled by the error handler. I have...
11
6564
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am...
3
5783
by: Eric | last post by:
Hi. I have this Combobox name 'Origin' that contains all states and countries. I would like to create two Radio buttons (State and Country) that when you select State, the combobox will query only the states and vice versa for country. I've create two columns in the Origin table (OriginState and OriginCountry) and set the data type to 'bit'...
4
3418
by: JHite | last post by:
I am using Access 2003 on Windows XP. This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusReports” containing the “StafferID” (link to Staffer table), the “ProjectID” (link to Projects table), a “Date” field, and a “Notes” field. ...
0
7666
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...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
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...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1201
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.