If user uses CTRL+S to save, instead of my Save buttons that is fine, because the before and after update subs run for both ways of saving.
However, if user uses CTRL+Z, instead of my Cancel buttons, disaster strikes!
In one form in particular, it's a big problem. By the time a whole record has been put in, if the user clicks Cancel quite a lot of processing needs to be undone, and it all works fine, but this code is in the Cancel sub. If the user uses CTRL+Z the Cancel sub is bypassed and none of the undo-processing is done.
Trouble is, Cancel does not trigger 'before' or 'after update', or, as far as I can ascertain, any other Form event (I've put msgboxes in all sorts of hopeful places!), so there there seems nowhere to put my 'undoing' code.
Can anyone suggest any way of trapping the CTRL+Z? I've messed about with KeyPreview and KeyDown, but I although I can make a 'beep' when CTRL is pressed I can't seem to pick up the Z as well, or stop the whole CTRL+Z being acted on?
I'm not sure I fully follow the logic of what you're trying to achieve here Juliet, but the following template should enable you to proceed. You probably won't need both Cancel and Ctrl-Z, but it's clear how to fix for your particular requirement. - 'Form_KeyDown only runs if the form's .KeyPreview property is True.
-
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
Select Case True
-
Case ((Shift = acCtrlMask) And (KeyCode = vbKeyZ))
-
'Your Ctrl-Z action here
-
Case ((Shift = 0) And (KeyCode = vbKeyCancel))
-
'Your Cancel action here
-
End select
-
End Sub
5 5793
Hi Juliet
Set the KeyPreview' property of your form to 'Yes' then enter the following code in the 'KeyDown' property of your form. It will test for that combination and if true set the keycode to zero essentially cancelling out the keystroke. - Dim intCtrlDown As Integer
-
intCtrlDown = (acCtrlMask)
-
If intCtrlDown And KeyCode = vbKeyZ Then
-
Msgbox "Ctrl+Z was pressed"
-
KeyCode = 0
-
End If
NeoPa 32,556
Expert Mod 16PB
I'm not sure I fully follow the logic of what you're trying to achieve here Juliet, but the following template should enable you to proceed. You probably won't need both Cancel and Ctrl-Z, but it's clear how to fix for your particular requirement. - 'Form_KeyDown only runs if the form's .KeyPreview property is True.
-
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
Select Case True
-
Case ((Shift = acCtrlMask) And (KeyCode = vbKeyZ))
-
'Your Ctrl-Z action here
-
Case ((Shift = 0) And (KeyCode = vbKeyCancel))
-
'Your Cancel action here
-
End select
-
End Sub
Thank you very much. That's great. This is a nice bit of code for my 'how to' library!
However, whenever one of you experts says "I'm not sure I fully follow the logic of what you're trying to achieve here Juliet", I usually start to think it's probably something mad I'm trying to do, and re-think the overall approach, as I did here.
NeoPa 32,556
Expert Mod 16PB
Always a pleasure :)
In truth, that is a wise reaction generally, though sometimes it's as simple as difficulties of communication across a forum. Talking directly is so much easier and clearer, and having the database in front of you to refer to, so much easier again. We nevertheless must deal with the forum interface in most situations, so we live with a bit of confusion from time-to-time.
PS. If you've managed to find a more appropriate approach then I applaud you. I always see that as an important sign of growth, or development may be a better word.
There is a very simple, code-less, solution (6 characters) which can enable you to negate the Ctrl+Z sequence and that is the AutoKeys Macro. If you are interested, let me know. I'm not a hugh Macro fan, but AutoKeys is a specialized Macro, and I do not think that they are going anytime soon.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kai Grossjohann |
last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window.
That's fine, I don't need to do anything about it.
But Ctrl-N in IE appears to clone the current window. Is there a way
to...
|
by: Deano |
last post by:
Alot of my forms are bound.
I would like to offer a Cancel option so that they can make as many changes
as they like and still Cancel out without making any changes.
I have one idea of how to...
|
by: Alex K. |
last post by:
My MDI form has several child forms in maximized state. Pressing Ctrl-F6
causes next child to show, which I don't like. How can I cancel standard
Ctrl-F6 behaviour?
Thank you
|
by: amrita |
last post by:
hi
i have a table in web form wth name table1.i need that wen i click on cancel button all the textboxes in that table becomes empty.ny ideas how to do it,doin in onclien side wud be greatly...
|
by: John Dalberg |
last post by:
I have master/detail datagrids where each master row has a detail datagrid.
I have included a linkbutton in the child datagrid's footer to add a new
row. If I click on the add link in more than one...
|
by: Martin |
last post by:
I have a form with two submit buttons: <Save> and <Cancel>. When the
user clicks on <Save>, I want to execute a validate function. When he
clicks on <Cancel>, I want the form to submit without...
|
by: tim.cavins |
last post by:
I am trying a GridView for the first time and it seems to be something
that should be EXTREMELY simple.
I cannot get the Update or Cancel when trying to edit a row to work.
When I click on the...
|
by: Bob Alston |
last post by:
Anyone know how to disable or redefine the Ctrl - hotkey which deletes a
record? I have a multi page form that uses 14 records, each record
handles 1-2 pages of the 18 page form. Occasionally ,...
|
by: John Gault |
last post by:
I experimented with a snippet of JavaScript that will display a "Please
Wait" message and graphic while the results of a cgi script is running (the
script grabs a bunch of data and formats it in a...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
| |