View Full Version : Sendkeys "{ESC}" closes open form.


cool_archie
03-28-2005, 02:52 AM
Hello,

Sendkeys "{ESC}" closes open form.
Need Solution to use sendkeys "{ESC}" and keep the form open!

Regards,
Archie

dt01pqt
03-28-2005, 03:29 AM
This is not a good way to close a form. Use

Docmd.Close acForm, me.Name

If you want to cancel on the form unload event place:

[code]If MsgBox("Close Form?", vbOKCancel, "Close Form?") = vbCancel Then
Cancel = True
End If[code]

modest
03-28-2005, 11:32 AM
Archie,

If you don't delete your other duplicate threads... never expect an answer from me. In my opinion posting multiple times demonstrates ignorance and not urgency - and ignorance upsets me. Please go back and do your part in cleaning up the forum.

Modest

cool_archie
03-28-2005, 11:26 PM
Well I really dont know how this message got posted so many times.

Neways I have deleted the duplicate messages.

cool_archie
03-28-2005, 11:31 PM
This is not a good way to close a form. Use

Docmd.Close acForm, me.Name

If you want to cancel on the form unload event place:

[code]If MsgBox("Close Form?", vbOKCancel, "Close Form?") = vbCancel Then
Cancel = True
End If[code]


Well I am not closing the form using Sendkeys...
I am using it to undo a value entered in a field once the user cancels instead of saving, I am using Sendkeys.. instead of me.undo cause sendkeys restores the previous data in a field while keeping focus on the feild, whereas me.undo doesn't so i want a solution to do what I just mentioned above.

Regards,
Archie

ghudson
03-29-2005, 08:01 AM
SendKeys is not the way to go. You should avoid using the SendKeys.

Check the Access help files [or search here] on how to use the .OldValue property.

modest
03-29-2005, 11:14 AM
Well I really dont know how this message got posted so many times.

Neways I have deleted the duplicate messages.

Thank you :) -- I'll proceed to look at your problem.

I agree with Hudson, Sendkeys isn't just not a good way.. it's fickle. Let me look through my database for something I did before.

modest
03-29-2005, 11:21 AM
I'm not sure if it restores what was previsouly there, but I just created a "Cancel" button and use the following code with it:

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Try overriding your {ESC} preset with it.

-Modest

ghudson
03-29-2005, 01:41 PM
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
-Modest
Outdated menu command option. :eek: Use the DoCmd.RunCommand's instead.

DoCmd.RunCommand acCmdUndoThe .OldValue property will allow you to return the specified fields value to what it originally was for a bound form. I use it often in the AfterUpdate event of a combo box. I ask if the user "if" they meant to change the combo box value of an old record. This prevents the user from editing an old record when they should have started a new record and then selected a value in a combo box.

modest
03-29-2005, 01:54 PM
Outdated menu command option. :eek:

"Let me look through my database for something I did before." ... I just didn't say how long ago I did it :) By the way RunCommand still pulls from the menu. It's just the new way of doing it.