By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 3,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

SendKeys - is it error-prone?

P: n/a
MLH
I have the following code with a SendKeys statement in it.

100 If Me.Dirty Then
MsgBox "Form is Dirty!"
120 Dim MyQ As String, MyTitle As String, Response As Boolean
140 MyQ = "You started to enter something. Are you sure you
want to quit without saving?"
180 MyTitle = "Continue? - " & MyApp$ & ", rev. " & MY_VERSION$
240 Response = AskUserQ(MyQ, MyTitle, vbQuestion,
vbDefaultButton1)
MsgBox "RESPONSE: " & CStr(Response)
260 If Response = True Then ' User chose Yes.
MsgBox "I am about to send the ESC character."
280 SendKeys "{ESC}"
MsgBox "I just sent the ESC character. The form should have cleared."
300 Forms(Me.OpenArgs).Visible = True
320 DoCmd.Close acForm, ThisForm
340 Else ' User chose No.
360 Exit Sub
380 End If
400 Else
MsgBox "Form is NOT Dirty!"
410 If Not IsNull(Me.OpenArgs) Then
440 Forms(Me.OpenArgs).Visible = True
445 DoCmd.Close acForm, ThisForm
450 Else
460 DoCmd.Close acForm, ThisForm
465 End If
480 End If

If I leave line #280 effective - the msgbox following it never
displays. If I REM it out, that same msgbox DOES display.
Did microsoft mean for the sendkeys statement to override
the following msgbox command? Or, is that a bug? A97.
Jun 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
searched the NG and found this...

From: Larry Linson - view profile
Date: Fri, Sep 24 2004 2:24 pm
Email: "Larry Linson" <boun...@localhost.not>
Groups: comp.databases.ms-access
Not yet rated
Rating:
show options

Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author

Try

DoCmd.RunCommand acCmdUndo

SendKeys "{Esc},{Esc}" works, too. Because it isn't language dependent
as
some Menu commands are, it is a more reliable use of SendKeys.

Larry Linson
Microsoft Access MVP

"Tim Marshall" <TIM...@antarctic.flowerpots> wrote in message

news:cj**********@coranto.ucs.mun.ca...

- Hide quoted text -
- Show quoted text -
What is the docmd.runcommand accmd? for the equivalent of pressing the
escape button when adding a record to a table? I'm setting up a bound form and would like to have a "cancel" button
that does this. Thanks in advance.
--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Reply Rate this post: Text for clearing space

3
From: Tim Marshall - view profile
Date: Fri, Sep 24 2004 3:59 pm
Email: Tim Marshall <TIM...@antarctic.flowerpots>
Groups: comp.databases.ms-access
Not yet rated
Rating:
show options

Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author

Larry Linson wrote: DoCmd.RunCommand acCmdUndo


That does the trick, thanks very much.

--
Tim - http://www.ucs.mun.ca/~tmarshal/

Jun 21 '06 #2

P: n/a
Sendkeys in virtually every situation should be your absolute last resort.

What SendKeys does is send a key stroke to whichever window has the focus,
in your example below it is the Msgbox which is why you don't see it, it's
getting dismissed before it has time to paint.

Look at the difference between the two following lines of code, you can run
these from the debug window

sendkeys "{esc}":msgbox "OK"
and
sendkeys "{esc}":doevents:msgbox "OK"

With the first line of code there is a slight flick of the screen and the
message box doesn't appear, with the second line of code the doevents causes
the application to cede control temporarily, therefore the esc keystroke is
sent before the msgbox call, so you do get to see the message box.

--

Terry Kreft
"MLH" <CR**@NorthState.net> wrote in message
news:u9********************************@4ax.com...
I have the following code with a SendKeys statement in it.

100 If Me.Dirty Then
MsgBox "Form is Dirty!"
120 Dim MyQ As String, MyTitle As String, Response As Boolean
140 MyQ = "You started to enter something. Are you sure you
want to quit without saving?"
180 MyTitle = "Continue? - " & MyApp$ & ", rev. " & MY_VERSION$
240 Response = AskUserQ(MyQ, MyTitle, vbQuestion,
vbDefaultButton1)
MsgBox "RESPONSE: " & CStr(Response)
260 If Response = True Then ' User chose Yes.
MsgBox "I am about to send the ESC character."
280 SendKeys "{ESC}"
MsgBox "I just sent the ESC character. The form should have cleared."
300 Forms(Me.OpenArgs).Visible = True
320 DoCmd.Close acForm, ThisForm
340 Else ' User chose No.
360 Exit Sub
380 End If
400 Else
MsgBox "Form is NOT Dirty!"
410 If Not IsNull(Me.OpenArgs) Then
440 Forms(Me.OpenArgs).Visible = True
445 DoCmd.Close acForm, ThisForm
450 Else
460 DoCmd.Close acForm, ThisForm
465 End If
480 End If

If I leave line #280 effective - the msgbox following it never
displays. If I REM it out, that same msgbox DOES display.
Did microsoft mean for the sendkeys statement to override
the following msgbox command? Or, is that a bug? A97.

Jun 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.