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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The word macro below is supposed to

Status
Not open for further replies.

RH610

Programmer
Aug 7, 2001
152
0
0
US
The word macro below is supposed to open an access database. The database puts up a form which gets some user input and creates a text file with some addresses in it and then closes. Upon close of Access, control is supposed to return to Word, which is then supposed to insert an envelope for each address in the text file that was created with Access. The Access database opens fine and produces the text file (it does have addresses in it), but it looks like Word is just going ahead without waiting for Access to return. Word just inserts an envelope before Access does its processing. Any way to get Word to wait at the point it goes to Access for Access to get done before proceeding?

Thanks

Sub test()

Dim ad$(20)
Dim AccessApp As Object
Set AccessApp = CreateObject("access.application")
AccessApp.Visible = True
AccessApp.openCurrentDatabase "c:\temp\test.mdb"

Close 1
Open "c:\temp\test.txt" For Input As 1
Do While Not EOF(1)
Line Input #1, add$

ActiveDocument.Envelope.Insert ExtractAddress:=False, OmitReturnAddress _
:=True, PrintBarCode:=True, PrintFIMA:=True, Height:=InchesToPoints(4.13 _
), Width:=InchesToPoints(9.5), Address:=Add$, AutoText:= _
"ToolsCreateLabels3", ReturnAddress:="", ReturnAutoText:= _
"ToolsCreateLabels4", AddressFromLeft:=wdAutoPosition, AddressFromTop:= _
wdAutoPosition, ReturnAddressFromLeft:=wdAutoPosition, _
ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation:=wdLeftLandscape _
, DefaultFaceUp:=True

Loop

End Sub

 
I have a brute force solution. I humbly defer to anyone who has the "proper" solution; but since your question is not getting any grease, I hope you'll appreciate this much, despite my personal embarassment at this banality [tongue]

I don't use the correct way to communicate between processes because I've been barbequed over the years (with DDE or whatever) by either their unreliability or processes locking hanging system (#$%^&!!) or just all the crap needed to code and get it running. So I'm going to give you the Tina Turner system for intercommunitation between apps.

Have Word delete a uniquely named file, which we'll call the "flag file."
Call Access.
The last thing Access does is create the flag file.
Then in Word, prior to the code that is dependent on Access' action, have While NotExists(myfile):wend
[sub](I miss being able to put "Yield" in there too. Hey, some of us aren't vicious roadhogs :) ) [/sub]

Your NotExists can just use "Open myFile..." and errorlevel, if nothing else. (I don't recall a direct built-in function for that)

It ain't slick but at least it slides.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top