Sendkeys in Office 2003

B

B.S.R.

We recently upgraded from Office 97 to Office 2003 and have noticed that our
SendKeys function no longer works. We use it when programmatically printing
a report to Adobe PDF; we loop through a variable (e.g. "Department") and
print the report once for each department. We use the SendKeys function to
pass along the name and directory location of the file to be saved, as well
as to hit "Enter".

Do any of you know of how SendKeys may have changed in Office 2003? I've
been trying to debug it and I know that the keys are being sent, it's just
that the timing is off. I've tried putting the Sendkeys both before and
after the code that prints the report.

Thanks in advance for your advice!
 
S

SacCourt

The "True" and "False" flag may work differently in Access 2003. The fale is
supposed to wait and seems to execute the command at the typographic rate set
in control pannel.

Often you will send the keys before the menu or Widnows screen is ready to
take the keystrokes. In that case the keys are sent and you get nothing.
Sometimes the first few keystrokes are lost in a transmission.

I uses several techniques to defeat the timeing of a macro.



I use the "{home}" key as a nonsense time waster. For example,

SendKeys "{home 100}Then your important commands", true

Then if 1 to 99 of the {home} keystrokes is truncated you still get your
critical data.

Here is where the true and false swith comes into play, I think, 100
keystrokes under true thaks about a second. 100 keystorkes under false may
take 3-10 seconds.

I will set up a useless loop in visual basic to wast some time and let a
window open or a dialog box to appear.

Dim Wwait

For Wwait = 1 to 1000000
next WWait

If you want to waste some time in a loop like this at 1 gig your loop needs
to be big.

I also use the timer interval to send code at specific times when my target
applicaiton is very sluggish.

This is all sloppy coding and what I call brute force to accomplish your
goals. But it can be the difference between getting the job done or not.

I order to be certian I often must use both in the same macro.

You may have better luck with the domnu commands. Often you have very good
direct commands to accomplish your goal. SendKeys are my last resort usually
when controlling legacy applicaitons by Access.

DoCmd.RunCommand acCmdSelectAll
DoCmd.RunCommand acCmdRecordsGoToFirst
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPaste
DoCmd.RunCommand acCmdPasteAppend
DoCmd.RunCommand acCmdFind
DoCmd.RunSQL "DELETE ZF18.Document_Date FROM ZF18 WHERE
(((ZF18.Document_Date) Is Not Null));"
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.Maximize
DoCmd.DeleteObject acTable, "ZF18"
DoCmd.Close acForm, "Menu", acSaveYes
DoCmd.OpenForm "Menu"

Some examples that are very usefull.

Direct commands are always better than SendKeys
examples when working from within Access. They do not present timing
issues, they don't run out of order, and they give a much more depenable
result.
 

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

Top