Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Please consider donating $1 per sample downloaded, find out why here. If downloading multiple samples, please donate once for all of them.
Amazon Honor System  Click Here
to Pay Learn More
Access-L FAQ (Forum Locked Forum Locked)
 RAL Forums : Access-L FAQ
Subject Topic: the evils of SendKeys Post ReplyPost New Topic
Message << Prev Topic | Next Topic >>

Joined: 30 September 2002
Location: United States
Posts: 120
Posted: 06 October 2004 at 6:03pm | IP Logged Quote -Francisco


While everyone on the list is correct and you shouldn't use SendKeys let me explain why it wasn't working for you (just so you'll know).

The SendKeys command puts into the keyboard buffer the individual keystrokes you program. Since Access doesn't control the keyboard buffer those keystrokes get used by the buffer in the first place it can. So you're keystrokes, while put in the buffer by Access, could just as easily end up in a Notepad file if that app had the focus at the exact moment the SendKeys command was executed. Or the keystrokes could end up in a field on a Form in your MDB that is open. There's no telling where they will end up.

That's not exactly why your little code sample wasn't working but some background information to help understand why using SendKeys is such a bad idea. The reason your little Function didn't work is because you didn't put the keystrokes into the buffer BEFORE you created your message box. SendKeys has to put the keystrokes into the buffer before you can do anything with them. So your MsgBox line needs to be after the SendKeys lines. However, that still won't work because you're sending 2 returns or "Enters" to the buffer. The first would close your message box as quickly as it was opened and the second would do something depending on how the Function was being executed. If you had it as the code under a button and that button was the only one on a Form or just kept the focus after it was clicked then you'd set up a never ending loop (you click the button, SendKeys put 2 "enters" into the buffer, a message box is created, the first "enter" closes the message box, the second "Enter" has the same effect as clicking the button again and you repeat until you stop the code, force a close of the app or turn off the computer).


Alan Fisher

-----Original Message-----

Date: Wed, 6 Oct 2004 15:04:20 -0400 From: Anne Smith Subject: SendKeys

I'd like to be able to pop-up a message box and then close it automatically without requiring the user to do it. My program is:

Function test() MsgBox "hello" SendKeys "~" SendKeys "{ENTER}" End Function

It doesn't work with either of the SendKeys commands. Does anyone know if there is a way to do this.

Basically, I need it because my program runs an executable that writes to a file and then has to read from it. The only way to ensure that it finishes writing seems to be to use the MsgBox command. Even if I have a loop that goes to 100,000, sometimes it just hangs. The MsgBox command does the trick every time. I just don't want to burden the users with having to click OK each time.

Any ideas?




Back to Top View -Francisco's Profile Search for other posts by -Francisco Send Private Message Add to Buddy List

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.01
Copyright ©2001-2003 Web Wiz Guide