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.