Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sendkeys to fast problem

Status
Not open for further replies.

DBritter

Technical User
Jun 28, 2000
37
US
I am having trouble with one of my modules. It is sending the key too quickly and document does not open. Here is the section that has the problems:

OpenWord = Shell("C:\Program Files\Microsoft Office\Office\WINWORD.EXE", 1)
SendKeys "%(fo)"
SendKeys " \\NDS2\MktgDB\MailMergeLetters\Copy of NewGeneralLetter120899", True
SendKeys "% (o)", True
SendKeys "% (o)", True
SendKeys "% (trmm)", True'Merges letter to query
SendKeys "^ (p)", True'print letter
SendKeys "{enter}", True
SendKeys "% ({f4})", True'close letter
SendKeys "% (nn)", True'do not save letter

1. Is there a way to make it wait for the document to be found? It is just taking a while to find the document on the network.
2. Is there a way to automate the mailmerge that is going on here without sending keys?
Thanks,
Dave
 
I dont know if this will help but have you tried using:-

'Do Events'

this command tells access to go away and do anythig else that needs doing. I use it in a while loop waiting for a form to close.

While me!fldState = &quot;<Waiting>&quot;
Do events
wend

this puts access into a loop until the form field fldState is changed (by the form itself) to anything other than &quot;<Waiting>&quot;. Maybe you could try something like the following:-

sendkeys &quot;string&quot;
lngTimer = Time
while time < (lngTimer + 10000)
do events
wend

Regards
Kirk
 
Dave,
With MSACCESS and WORD you can use DDE (although antiquated) it is still a better option the sendkeys
Scoty
 
I did a &quot;mail merge&quot; to word... but I didn't use the MailMerge feature. I put bookmarks in the document where the data would end up and used SQL and some Word Object functions to populate the document.

If you want, I can give you more info on that next week. I attached a button to a form to start the &quot;merge&quot; process.

Mary :eek:)
 
I would be grateful for more information on populating the word document.
 
Hello DBritter!

I have hade the same problem, and recently I found a
useful way to avoid it. Call WindowWait with e.g.
App = &quot;Untitled - Notepad&quot; if that's what you are
waiting for. Works nicely, but so far I have not
been able to find out what the name of an arbitrary
active window is. If you do, please tell me how!

(You can easily add a timeout mechanism in the
procedure below.)


Private Sub WindowWait(App)
' App = Program title in the Title Bar
On Error GoTo wWait
ActivateTry:
AppActivate App
On Error GoTo 0
Exit Sub
wWait:
Delay 0.2
Resume ActivateTry
End SubPrivate

Sub Delay(dt)
Dim t
t = Timer + dt
While Timer < t
DoEvents
Wend
End Sub

Good luck and best regards, Hans-Göran
 
and, DBritter, another thing: You still will often need
a little pause between you Sendkeys, so use this routine
instead:

Private Sub Sk(cmd)
Delay 0.2
SendKeys cmd, Wait:=Yes
End Sub

(I noticed that the &quot;Private&quot; part in Delay was in
the wrong line in my previous message, you'll fix
that.)

/bye, HGB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top