Hey guys,
I hope someone can help me out. I am attmepting to automate a mail merge. First let me descripe my problem. I am working on autoamtically faxing information from an access database. I dont want to print this stuff to letter head so I created a mailmerge document on word which has the letterhead (bitmaps) already attached in the header and footer. So now I fake-automate using send keys. This works fo about 2 seconds as the system times are upredictable at best. So I decide to OLE/COM automate. This is my first time to try this in a office app to office app situation. I have had success in other automation projects. But this one is turning into a real nightmare. I am running office97 on Win NT v4.0 build 6. Here is my code:
Now the first time through the loop this works great but the next time through the loop I get this error
The continue is greyed out. The debug takes me to the line:
I know it is something I am overlooking. Please help if me. I need to make this work soon.
Thanks
Scoty
I hope someone can help me out. I am attmepting to automate a mail merge. First let me descripe my problem. I am working on autoamtically faxing information from an access database. I dont want to print this stuff to letter head so I created a mailmerge document on word which has the letterhead (bitmaps) already attached in the header and footer. So now I fake-automate using send keys. This works fo about 2 seconds as the system times are upredictable at best. So I decide to OLE/COM automate. This is my first time to try this in a office app to office app situation. I have had success in other automation projects. But this one is turning into a real nightmare. I am running office97 on Win NT v4.0 build 6. Here is my code:
Code:
Private Sub Command10_Click()
Dim wd As Object
Dim regcnt As Integer
Dim z As Integer
Dim y As Double
Dim ID As Variant
Dim name As Variant
regcnt = Me.List6.ListCount
regcnt = regcnt - 1
For z = 0 To regcnt
Set wd = CreateObject("Word.Application") 'create the word object
name = "g:\netdrive\Scottys\faxdocs\temp" & z & ".doc" ' create a name for the new document
DoCmd.GoToControl "List6"
List6.Selected(z) = True
DoCmd.GoToControl "Command10"
ID = Mid(List6.Value, 16, Len(List6))
text8 = ID ' the record number used to produce the merge
wd.Application.Visible = True 'open word
Application.Documents.Open "g:\netdrive\Scottys\faxdocs\LHFax.doc" ' open letter head fax document
Do Until y = 15000000: y = y + 2: y = y - 1: Loop: y = 0 'Timer loop
ActiveDocument.MailMerge.Execute 'make the merge
ActiveDocument.SaveAs FileName:=name 'save the new doc as the value of name
Documents("LHFax.doc").Close False 'close orig merge doc with out saving
wd.Application.Quit ' close word
Set wd = Nothing 'destroy object
Next z
Code:
+-----------------------------------------+
|Run-Time error '-2147023174 (800706ba)': |
| |
|Automation error |
|The RPC server is unavailable |
| |
| _____ ________ _______ _______ |
| |Debug| |Continue| | End | | Help | |
| ----- -------- ------- ------- |
+-----------------------------------------+
Code:
ActiveDocument.MailMerge.Execute
I know it is something I am overlooking. Please help if me. I need to make this work soon.
Thanks
Scoty