If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How Best to Disable ESC Key on Form
My problem surrounds the ESC key function by design within Access. In my
office we have a major departmental database being accessed by 20-30 users at any given time. 1. This is NOT an issue of the number of simultaneous users. 2. It IS a problem of users ACCIDENTALLY hitting ESC ocassionally while they are entering data into this database. + The users are using this database and another commercial database (non-Access, which has different functional use for the ESC key than in Access) toggling back and forth between these databases. While my director would like the ESC disabled for this database, I am thinking that I might be better if we were able to "fix" the real issue by disabling it on select forms, one at a time as needed. One user suggested that it might be useful to have a "check" message box seeking the user's confirmation BEFORE clearing in the event the ESC key is hit. If the user does NOT confirm, then data remains as entered. What would be the BEST way to approach this fix? Thank you in advance for your assistance. -- MJ |
#2
|
|||
|
|||
How Best to Disable ESC Key on Form
You could just enter the following code to your entry form:
Private EscapePressed As Boolean Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) EscapePressed = (KeyCode = 27) End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If EscapePressed Then If MsgBox("Leave this form?", vbExclamation + vbOKCancel, "Attention!!!") = vbCancel Then Cancel = 1 EscapePressed = False End If End If End Sub Regards JM "MJ" schreef in bericht ... My problem surrounds the ESC key function by design within Access. In my office we have a major departmental database being accessed by 20-30 users at any given time. 1. This is NOT an issue of the number of simultaneous users. 2. It IS a problem of users ACCIDENTALLY hitting ESC ocassionally while they are entering data into this database. + The users are using this database and another commercial database (non-Access, which has different functional use for the ESC key than in Access) toggling back and forth between these databases. While my director would like the ESC disabled for this database, I am thinking that I might be better if we were able to "fix" the real issue by disabling it on select forms, one at a time as needed. One user suggested that it might be useful to have a "check" message box seeking the user's confirmation BEFORE clearing in the event the ESC key is hit. If the user does NOT confirm, then data remains as entered. What would be the BEST way to approach this fix? Thank you in advance for your assistance. -- MJ |
#3
|
|||
|
|||
How Best to Disable ESC Key on Form
JM,
Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, -- MJ "Joop Muis (@Home)" wrote: You could just enter the following code to your entry form: Private EscapePressed As Boolean Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) EscapePressed = (KeyCode = 27) End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If EscapePressed Then If MsgBox("Leave this form?", vbExclamation + vbOKCancel, "Attention!!!") = vbCancel Then Cancel = 1 EscapePressed = False End If End If End Sub Regards JM "MJ" schreef in bericht ... My problem surrounds the ESC key function by design within Access. In my office we have a major departmental database being accessed by 20-30 users at any given time. 1. This is NOT an issue of the number of simultaneous users. 2. It IS a problem of users ACCIDENTALLY hitting ESC ocassionally while they are entering data into this database. + The users are using this database and another commercial database (non-Access, which has different functional use for the ESC key than in Access) toggling back and forth between these databases. While my director would like the ESC disabled for this database, I am thinking that I might be better if we were able to "fix" the real issue by disabling it on select forms, one at a time as needed. One user suggested that it might be useful to have a "check" message box seeking the user's confirmation BEFORE clearing in the event the ESC key is hit. If the user does NOT confirm, then data remains as entered. What would be the BEST way to approach this fix? Thank you in advance for your assistance. -- MJ . |
#4
|
|||
|
|||
How Best to Disable ESC Key on Form
On Wed, 10 Mar 2010 09:52:08 -0800, MJ wrote:
JM, Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, Just use AS Integer - since you're using an Access Form rather than a Microsoft Forms form (I presume). You'll also need to set the form's KeyPreview property to Yes. -- John W. Vinson [MVP] |
#5
|
|||
|
|||
How Best to Disable ESC Key on Form
If you want to disable the ESCape key on a form you can use
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then 'Debug.Print "Escape key pressed" KeyCode = 0 'Cancel the key stroke End If End Sub You will need to set the form's Key Preview property to True. If you want the user to have options you need to insert something where I have the commented out Debug. Perhaps lines like the following If MsgBox("Undo changes?",vbYesNo,"What?") = vbNo Then KeyCode = 0 End If John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County MJ wrote: JM, Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, |
#6
|
|||
|
|||
How Best to Disable ESC Key on Form
John,
Thank you for your inputs, that fixed the compile error. -- MJ "John W. Vinson" wrote: On Wed, 10 Mar 2010 09:52:08 -0800, MJ wrote: JM, Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, Just use AS Integer - since you're using an Access Form rather than a Microsoft Forms form (I presume). You'll also need to set the form's KeyPreview property to Yes. -- John W. Vinson [MVP] . |
#7
|
|||
|
|||
How Best to Disable ESC Key on Form
JM,
Changed the MSForms.ReturnInteger to Integer and fixed the compile error (per John W. Vinson's suggestion) and set KeyPreview to Yes, but did not get the results I was expecting. 1) The KeyDown SP seems to have broken all movement from field to field on the form. 2) When ESC key was pressed, never got to the error message box. Do you have any further suggestions? Thank you for your time and inputs. -- MJ "Joop Muis (@Home)" wrote: You could just enter the following code to your entry form: Private EscapePressed As Boolean Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) EscapePressed = (KeyCode = 27) End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If EscapePressed Then If MsgBox("Leave this form?", vbExclamation + vbOKCancel, "Attention!!!") = vbCancel Then Cancel = 1 EscapePressed = False End If End If End Sub Regards JM "MJ" schreef in bericht ... My problem surrounds the ESC key function by design within Access. In my office we have a major departmental database being accessed by 20-30 users at any given time. 1. This is NOT an issue of the number of simultaneous users. 2. It IS a problem of users ACCIDENTALLY hitting ESC ocassionally while they are entering data into this database. + The users are using this database and another commercial database (non-Access, which has different functional use for the ESC key than in Access) toggling back and forth between these databases. While my director would like the ESC disabled for this database, I am thinking that I might be better if we were able to "fix" the real issue by disabling it on select forms, one at a time as needed. One user suggested that it might be useful to have a "check" message box seeking the user's confirmation BEFORE clearing in the event the ESC key is hit. If the user does NOT confirm, then data remains as entered. What would be the BEST way to approach this fix? Thank you in advance for your assistance. -- MJ . |
#8
|
|||
|
|||
How Best to Disable ESC Key on Form
John,
Your reply did get me "closer" to the the results I was looking for, but not quite there yet. 1) Your code for SR KeyUP with modification for msgbox... Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then 'Debug.Print "Escape key pressed" If MsgBox(" Do you want to CLEAR changes?", vbExclamation + vbOKCancel, "ESC Key Hit... What?") = vbCancel Then KeyCode = 0 'Cancel the key stroke End If End If End Sub ... it recognized that ESC key was hit and got me to the msgbox question, but it DID NOT prevent clearing of data already entered into the form. 2) Preventing the clearing of data entry is PARAMOUNT, so do you have any suggestions on how to do that? Thanks again for the help. -- MJ "John Spencer" wrote: If you want to disable the ESCape key on a form you can use Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then 'Debug.Print "Escape key pressed" KeyCode = 0 'Cancel the key stroke End If End Sub You will need to set the form's Key Preview property to True. If you want the user to have options you need to insert something where I have the commented out Debug. Perhaps lines like the following If MsgBox("Undo changes?",vbYesNo,"What?") = vbNo Then KeyCode = 0 End If John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County MJ wrote: JM, Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, . |
#9
|
|||
|
|||
How Best to Disable ESC Key on Form
JM,
Changed the MSForms.ReturnInteger to Integer and fixed the compile error (per John W. Vinson's suggestion) and set KeyPreview to Yes, but did not get the results I was expecting. 1) The KeyDown SP seems to have broken all movement from field to field on the form. 2) When ESC key was pressed, never got to the error message box. Do you have any further suggestions? Thank you for your time and inputs. -- MJ "MJ" wrote: JM, Thank you for your reply. I must be missing somethng though, when I do a debug on the code you sent, I get a "compile error: user-defined type not defined". What am I missing? Thanks again for the inputs, -- MJ "Joop Muis (@Home)" wrote: You could just enter the following code to your entry form: Private EscapePressed As Boolean Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) EscapePressed = (KeyCode = 27) End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If EscapePressed Then If MsgBox("Leave this form?", vbExclamation + vbOKCancel, "Attention!!!") = vbCancel Then Cancel = 1 EscapePressed = False End If End If End Sub Regards JM "MJ" schreef in bericht ... My problem surrounds the ESC key function by design within Access. In my office we have a major departmental database being accessed by 20-30 users at any given time. 1. This is NOT an issue of the number of simultaneous users. 2. It IS a problem of users ACCIDENTALLY hitting ESC ocassionally while they are entering data into this database. + The users are using this database and another commercial database (non-Access, which has different functional use for the ESC key than in Access) toggling back and forth between these databases. While my director would like the ESC disabled for this database, I am thinking that I might be better if we were able to "fix" the real issue by disabling it on select forms, one at a time as needed. One user suggested that it might be useful to have a "check" message box seeking the user's confirmation BEFORE clearing in the event the ESC key is hit. If the user does NOT confirm, then data remains as entered. What would be the BEST way to approach this fix? Thank you in advance for your assistance. -- MJ . |
#10
|
|||
|
|||
How Best to Disable ESC Key on Form
hi,
On 10.03.2010 06:52, MJ wrote: What would be the BEST way to approach this fix? I would take a look at the Form Undo event: Private Sub Form_Undo(Cancel As Integer) Cancel = (MsgBox("Undo changes?", vbQuestion+vbYesNo) vbYes) End Sub mfG -- stefan -- |
|
Thread Tools | |
Display Modes | |
|
|