SendKeys VBA question

G

Guest

Hey, I've got this code:

Function MyMacro()
Dim ReturnValue
ReturnValue = Shell("C:\NOVELL\GroupWise\grpwise.exe", 1)
AppActivate ReturnValue, 1
SendKeys "^M", 1

Control+M is supposed to open a new mail message, but nothing happens and I
don't get an error message. The AppActivate line works fine and opens our
e-mail application, but the "^M" doesn't open a new mail item. Any hints?
I've tried "^{M}" and everything else I know of.

The other funny thing is that if I already have grpwise.exe running when I
execute the code, the "^M" works like it is supposed to. The grpwise window
is activated and a new mail message is started.

Thanks!
 
T

Tony Toews [MVP]

Mark1 said:
Hey, I've got this code:

Sendkeys are dangerous as the wrong app can get the focus or weird
things can happen.

See if there's an answer at one of the links on the following page.

Microsoft Access Email FAQ - Novell GroupWise
http://www.granite.ab.ca/access/email/novellgroupwise.htm
The other funny thing is that if I already have grpwise.exe running when I
execute the code, the "^M" works like it is supposed to. The grpwise window
is activated and a new mail message is started.

That's because your code isn't waiting for grpwise to complete
starting up. Insert a couple of doevents in there and see what
happens.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
G

Guest

Mark: Tony is very correct, SendKeys are dangerous - and are tricky - but
sometimes they may be unavoidable.

What I have done when I can't avoid SendKeys is include this module in the
application to accommodate pauses:

Option Compare Database
Option Explicit
Public Function Pause(PauseSeconds As Integer)
Dim Start
Start = Timer
Do While Timer < Start + PauseSeconds
DoEvents
Loop
End Function

Then I simply enter this line (for example) before the SendKey line ...

Pause 3

.... to pause for 3 seconds to wait for the second application (called from
Access) to catch up. Of course, you can use any time span (in seconds) you
need and you can use the pause anywhere you need it. Since I had to use it
several times in an app to get all the SendKey lines to function properly,
the Pause function was very handy.

Joe D
 
G

Guest

OK, thanks guys! Yeah, we use groupwise for e-mail and if it does talk to
MSAccess, I haven't figured it out yet. So, instead of just doing a
SendObject, I'm thinking that I have to send keys to it.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top