Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2005

Tip: Looking for answers? Try searching our database.

How do I accomplish the equivalent of hitting the {ESC} key in code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Reed - 29 Apr 2005 17:37 GMT
I have code at the end of the Before_Update event of an option group that
forces the user, by means of a MsgBox, to confirm his selection in the
option group. It works just fine, except that after canceling the update,
the record shows the little pencil up in the record selector, and the user
has to hit the {ESC} key to get rid of it. I have tried using SendKeys "
{ESC}" to no avail. Any suggestions? Here's the code:

strMsg = "You have selected " & strPhase & ". If this is correct, click
""OK""." & vbCrLf & _
        "If this is not correct, click ""Cancel"" and try again"
strTitle = "Confirm Phase Selection"
iResponse = MsgBox(strMsg, vbOKCancel + vbDefaultButton2 + vbInformation,
strTitle)
If iResponse = 2 Then DoCmd.CancelEvent
SendKeys "{ESC}"
End Sub
Robert Morley - 29 Apr 2005 18:21 GMT
You may need to play with the optional parameter of SendKeys and use:
   SendKeys "{ESC}", True 'or False, try both

You may want to try sending the ESC key a couple of times to be safe.

Also, if it's the Form update you're trying to cancel, instead try
   Me.Undo 'First time cancels the field update
   Me.Undo 'Second time cancels the form update

Rob

>I have code at the end of the Before_Update event of an option group that
> forces the user, by means of a MsgBox, to confirm his selection in the
[quoted text clipped - 12 lines]
> SendKeys "{ESC}"
> End Sub
Bill Reed - 30 Apr 2005 15:29 GMT
Thanks for the suggestions. I will try them out this morning. Meanwhile,
before I start another thread, maybe you can help me with my next question.

My form is incredibly slow before loading (I put a break in the on load
event and it takes forever before it even hits that code) and when going to
design of the form it takes just as long to display in design mode. I
suspect its because I am linking to a couple of mdbs on the server. If that
is the case, I could compile copies of those tables when I open my db. But
are you aware of any other reason why my form might be taking so long to
open, either in design or form view? I've been working on it for several
days now, does that have any effect on it's loading time?

Thanks,

Bill
Dirk Goldgar - 02 May 2005 01:40 GMT
> Thanks for the suggestions. I will try them out this morning.
> Meanwhile, before I start another thread, maybe you can help me with
[quoted text clipped - 9 lines]
> view? I've been working on it for several days now, does that have
> any effect on it's loading time?

One strong possibility, if you're using Access 2000 or later, is the
operation of the Name Autocorrect "misfeature".  Unless you really need
it, I suggest you turn it off:  Tools -> Options... -> General tab,
uncheck "Track name AutoCorrect info".  See if that makes a difference.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Bill Reed - 03 May 2005 19:39 GMT
Thanks to all of you for your sage advice. I will try all of your
suggestions.

Bill
John Nurick - 30 Apr 2005 17:57 GMT
Hi Bill,

When working in VBA it's always (or almost always?)) better to cancel an
event by using its Cancel argument. Normally in a BeforeUpdate event
you'd just do something along these lines:

 Dim strMsg As String
   
 strMsg = blah blah

 If MsgBox(strMsg, vbYesNo+vbQuestion) <> vbYes Then
   Cancel = True
 End If

which would return the user to editing the control (in this case the
option group).

If you also want to terminate editing the record you'd need something
like
    Me.Undo    'restore previous value of entire record
or
    Me.ActiveControl.Undo 'restore previous value of option group
    Me.Dirty = False 'force update of record.

>I have code at the end of the Before_Update event of an option group that
>forces the user, by means of a MsgBox, to confirm his selection in the
[quoted text clipped - 12 lines]
>SendKeys "{ESC}"
>End Sub

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.