Use word from Access (1 Viewer)

P

pstachel

Guest
In Access I have made a VBA module to open a Word document to insert some information from a Access data base to be printed. The module so far works but only once after system start. It does start if I start it a second time but stops a soon as I try to access any "ActiveDocument....) statement with a meassage :"The remote server-computer does not exist". If I shut down and reboot the coputer it does work properly once and stops at the second try as described.
I would not need Word if only Access could handle reports longer then 55 cm. Unfortunately my report is longer and I can not print it in 6 pixel writing, someone should be able to read it.
Either somebody can teach me how to create longer reports or I have to find a solution with the word problem.
Any help is appriciated.


:mad: See code below.


Private Sub Test_2()
'***************************************************************************************************
' Schreibt Produkt und Rezeptur in Word SDS
'
'*****************************************************************************************************
Dim stAppName As String
stAppName = "WINWORD.exe C:\Stachel\db3\Feld.doc"
Set oApp = CreateObject("Word.Application")

Call Shell(stAppName, 1)
MsgBox ("Vor Feld")
Debug.Print "Vor Active"
' at the second try it stops at this point and says "Remote-server does not exist ...."

ActiveDocument.Variables("Produkt").Value = "SMC ßßßßßßß"
Debug.Print " Nach Active"
ActiveDocument.Variables("Rezeptur").Value = "-----1/12"
ActiveDocument.Fields.Update
Debug.Print ActiveDocument.Variables(1).Name
Debug.Print ActiveDocument.Variables(2).Name
Debug.Print ActiveDocument.Variables(3).Name
Debug.Print "Nach Input Variablen"
Debug.Print "Active Document is: " & ActiveDocument.Name
MsgBox ("Nach Zoro")
oApp.Quit savechanges:=False
End Sub
 

bat1799

Registered User.
Local time
Today, 02:55
Joined
Nov 18, 2005
Messages
27
Not tested but this should work.
Code:
Dim appWord As Object
Dim wdDoc As Object
Dim strFilePath As String

strFilePath = "C:\Stachel\db3\Feld.doc"

Set appWord = CreateObject("Word.Application")
Set wdDoc = appWord.Documents.Open(strFilePath)

 wdDoc.Variables("Produkt").Value = "SMC ßßßßßßß"
 Debug.Print " Nach Active"
 wdDoc.Variables("Rezeptur").Value = "-----1/12"
 wdDoc.Fields.update
 Debug.Print wdDoc.Variables(1).Name
 Debug.Print wdDoc.Variables(2).Name
 Debug.Print wdDoc.Variables(3).Name
 Debug.Print "Nach Input Variablen"
 Debug.Print "Active Document is: " & wdDoc.Name
MsgBox ("Nach Zoro")

appWord.Quit savechanges:=False
Set wdDoc = Nothing
Set appWord = Nothing
End Sub

HTH
Peter
 
Last edited:
P

pstachel

Guest
Word from access

thanks bat1799,
I've tried your proposal. It opens word and the specified document but I get an error message "Application or Object defined error" as soon as an "wdDoc.ActiveDocument...." or "wdDoc.Variables...." statement is used.
Any explanation for that ??????
Thanks for replay.
 

Bat17

Registered User.
Local time
Today, 02:55
Joined
Sep 24, 2004
Messages
1,687
The code I posted tests ok for me apart from "Debug.Print wdDoc.Variables(3).Name" as only 2 variables were created.

Can you post the code that is actualy causing your error and I will see if I can see whats up.

peter
 
P

pstachel

Guest
Hello Bat17
this is the code I'd been using but got "Application or object defined error"

Private Sub Test_4()
Dim appWord As Object
Dim wdDoc As Object
Dim strFilePath As String
strFilePath = "C:\Stachel\db3\Feld.doc"
Set appWord = CreateObject("Word.Application")
Set wdDoc = appWord.Documents.Open(strFilePath, ReadOnly:=False)
appWord.Documents.Open strFilePath
appWord.Visible = True
wdDoc.Variables("Produkt").Value = "SMC ßßßßßßß" ' at this point I get the error message
Debug.Print " Nach Active"
wdDoc.Variables("Rezeptur").Value = "-----1/12"
wdDoc.Fields.Update
Debug.Print wdDoc.Variables(1).Name
Debug.Print wdDoc.Variables(2).Name
Debug.Print wdDoc.Variables(3).Name
Debug.Print "Nach Input Variablen"
Debug.Print "Active Document is: " & wdDoc.Name
appWord.Quit safechanges:=False
Set wdDoc = Nothing
Set appWord = Nothing

End Sub
 

Bat17

Registered User.
Local time
Today, 02:55
Joined
Sep 24, 2004
Messages
1,687
I have just tried it again with out hitting the error you have.
appWord.Quit safechanges:=False causes an error though!

My only thought is that it may be someting to do with differnt language version of word.
You could try checking in the object browser in Word VBA to see if Variables is there.

Peter
 

Users who are viewing this thread

Top Bottom