Shortcut Keys With Subforms

Lynn_AccessUser

Registered User.
Local time
Today, 14:00
Joined
Feb 4, 2003
Messages
125
I have a form with a subform. I am trying to add a shortcut key to a button which is enabled or disabled depending on whether a checkbox is checked or not. I need to put the code on the subform as well because the focus is sometimes on a field on the subform.

The code works fine except for one problem. When the checkbox is check hitting Crtl + R opens up a form which it should. The problem is when the checkbox is not checked it is suppose to open up a message box stating "HOSPITALIZED IS NOT CHECKED". When the user hits OK on the message box, it puts an R in the field on the subform because that is where the cursor was at when the user hit Crtl + R.

Here is the code on the subform.

If intctrl And KeyCode = vbKeyR Then
If IsNull(Forms!frm_Summary!Hospitalized) Or Forms! frm_Summary!Hospitalized = "" Then
MsgBox "HOSPITALIZED IS NOT CHECKED"
ElseIf Forms!frm_Summary!Hospitalized = 0 Then
MsgBox "HOSPITALIZED IS NOT CHECKED"
Else
DoCmd.OpenForm "frm_SummaryHospital", , , stLinkCriteria
End If
End If
 
I asssume that your code is not working as you expect because of how you are referencing the controls on the form or subform. The information you find here should help to to properly refer to controls on forms and subforms.

hth,
Jack
 
I understand what you are saying about referencing controls. However, do you think that is the problem considering it does reference the checkbox correctly and it is either suppose to open another form or a messagebox which it also does. The only problem is that it enters an R into the field on the subform if the cursor is on that field when the user hits Crtl + R and the messagebox opens. It does not do this when the second form opens.
 
Gotcha! I missunderstood your question. What you want to do is NOT have the R placed in the control when the user select Ctrl+R, right? Off the top of my head I do not now how to do this other than deleting the R from the control. What even are you using to see if the user has pressed Ctrl + R? Not sure I can solve your problem, but I will try to duplicate what you are getting...

Jack
 
The event I am using is on the subform itself. It is the On Key Down Event.

I messed around with code to try to get it to delete the R after the messagebox was closed, but I couldn't figure out how to do that. Also, I was worried if I started to delete things that it may accidently delete a record it wasn't suppose to.

Thanks for the help.
 
I'm sorry to take so long to get back to you but it has been a busy afternoon....

I put code like this in the On Key Press event of a control in a subform and it seemed to do what you want without the R being placed into the control:

If KeyAscii = 18 Then
MsgBox "Your Message"
...Rest of code...
End If

The Ascii 18 is Ctrl + R

I hope this helps and I will try to be faster if this does not work for you...

Jack
 
Last edited:
No problem with the response time . . . I know people are busy . . . appreciate your help.

I tried your code and nothing happens.

Here is my code with the change:

If KeyAscii = 18 Then
If IsNull(Forms!frm_Summary!Hospitalized) Or Forms!frm_Summary!Hospitalized = "" Then
MsgBox "HOSPITALIZED IS NOT CHECKED"
Undo
ElseIf Forms!frm_Summary!Hospitalized = 0 Then
MsgBox "HOSPITALIZED IS NOT CHECKED"
Undo
Else
DoCmd.OpenForm "frm_SummaryHospital", , , stLinkCriteria
End If
 
I just got a response from another newsgroup that I posted the question to. Here is the code:

If intctrl And KeyCode = vbKeyR Then
KeyCode = 0
rest of the code . . .
 

Users who are viewing this thread

Back
Top Bottom