Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ampersand shortcut and checkboxes 1

Status
Not open for further replies.

Fboo

Programmer
May 6, 2003
13
CA
Has anyone had experience with this problem? I find it very odd.

I have a form which has a 'Clear' button on it which clears all the fields in the form. The form consists mainly of date fields and checkboxes. I have used the '&' before the letter 'r' on my button so that users can press 'ALT + r' to clear the form rather than clicking on the 'Clear' button.

The only problem is that if you happen to have the focus on any of the checkboxes, typing 'r' alone will clear the form. In the case when you are in a checkbox, it is not necessary to use the 'ALT' key along with it. And this is not how I wish the form to operate.

Thank you for any help you can offer.
 
Brute force here:

on the "On Key Down" event for each of the checkboxes insert code that reassigns the KeyCode value so that it's anything but 82 (which apparently is the value of the R key)

Not sure you really want to do that, but it would solve your immediate problem.

Coley
 
Thank you Coley. I tried that but now the 'Alt + r' doesn't work. Also, I was hoping to not have to code every checkbox. But I do appreciate the help. :eek:)
 
Amend caltman's suggestion to check for the Alt key being down. If it is, do the clear. If it isn't don't.

Frank kegley
fkegley@hotmail.com
 
Thank you both. This is the code I am using. It seems to work. Does it look alright? So I suppose there isn't a way to simplify this? I guess I will have to call this code for every check box that I have. :eek:P *sigh*

Private Sub chkCheckBox_KeyDown(KeyCode As Integer, Shift As Integer)

'If Alt+r, Alt+c, Alt+s, Tab or the space bar is pressed then continue
If (KeyCode = 82) And (Shift And acAltMask) Or _
(KeyCode = 67) And (Shift And acAltMask) Or _
(KeyCode = 83) And (Shift And acAltMask) Or _
KeyCode = vbKeyTab Or _
KeyCode = vbKeySpace Then
Exit Sub
ElseIf (Shift <> acAltMask) Then
KeyCode = 0
End If

End Sub
 
Fboo,

Well, if you're using Access2000, in the form properties box there should be a property called: "Key Preview".

(From Access Help):
"You can use the KeyPreview property to specify whether the form-level keyboard event procedures are invoked before a control's keyboard event procedures."

You should be able to place code on the FORM's On Key Down property and not have to fight through adding it to each control.

Hope this helps.

Coley
 
Darnit - I meant to mention that you need to select "Yes" in the Key Preview property.

Sorry for the double post.

C
 
Wow, it worked wonders! Thank you so much Coley. I was just about to start coding every checkbox but decided to check my posting first. Definitely deserves a star! My headache is gone! :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top