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!

calling word from access

Status
Not open for further replies.

Trinitri

IS-IT--Management
Jun 10, 2003
12
CA
Hi I'm working on a database for distance learning. I'm using word to gernerate the report for the exam. The problem is that my application doesn't work without have word open. I'm trying to open a new word document from code but it's run good the first time but when I try to do it again it sends me an error telling me that can not open the server. Actually my aplication is local, so I don't now. What the code do is open a word document and add in the question for the exam which are on anothers word documents.
I send you the code. Please any sugestion would be really apreciated.
Thanks
Trinitri
' This funtion open a new word document application

Public Function sdf()

Dim oApp As Object

Set VarWord = New Word.Application

Set DocWord = VarWord.Documents.Add

VarWord.Visible = True

VarWord.WindowState = wdWindowStateMinimize


End Function

'This function prepare the format for the worddocument, add header and footer and the logo .

Public Function SheetFormat(Title, St, seed, Gen As String) As Boolean

sdf

With DocWord

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type

..........( design of the format)

End With

' This function generate the exam, is the one that I call when the user genetrate the exam, first run the format and after add the question.

Public Function exam(Title, St, seed, Gen As String) As Boolean

Dim SelTab As Recordset
Dim k As Integer
Dim MyName
Dim total As Integer
Dim sdxam As Variant
Dim Prt As Boolean
total = 0


Set MIB = CurrentDb()
Set SelTab = MIB.OpenRecordset(&quot;SelectionTable&quot;)

Prt = SheetFormat(Title, St, seed, Gen)

Do Until SelTab.EOF
total = total + SelTab![mark]

'( The var MyName is the path of the document who contains the question)

MyName = &quot;C:\Program Files\LManager\WordDoc\&quot; & SelTab![QuCode_qu] & &quot;.doc&quot;

With Selection

.InsertBefore (&quot;(&quot; & SelTab![mark] & &quot;) &quot; & SelTab![NoQuestion] & &quot;. &quot;)
.MoveDown
.InsertFile FileName:=MyName, ConfirmConversions:=False
.InsertParagraphAfter
.Collapse Direction:=wdCollapseEnd

End With
SelTab.MoveNext
Loop

With Selection
.TypeParagraph
.InsertBefore (&quot; &quot; & total)
.InsertParagraphBefore
.InsertBefore (&quot;________&quot;)
.InsertParagraphBefore
Selection.WholeStory
Selection.Font.Name = &quot;Times New Roman&quot;
Selection.Font.Name = &quot;Times New Roman&quot;
Selection.Font.Size = 12
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

End With
End function

Well hope that this help , please I need your help, thanks for your time
 
This should do it, you can either place a reference to a text field [text1] as the path, like below, or just change that to the path. The reason I have it set to Text1 is so that the administrator can change the path or name of the file if need be.

By the way this one opens, prints and then exits very quickly, it should only require a few modifications to keep it open.

Code:
Dim strPath As String
Dim objWord As Object
strPath = [Text1]
Set objWord = GetObject(strPath)
With objWord
    .Application.Visible = True
objWord.PrintOut Background:=False
End With
objWord.Application.Quit
Set objWord = Nothing

I have had a quick look through your code and I think I know why you are getting an error second time around, you are not reseting the value of [b]Set VarWord[/b]its remaining in memory you will need to add.

Set VarWord = Nothing

That should fix it.

let me know how you go.

Cheers

[afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake 
when you make it again.
 
Hi:

Thanks for your help but actually I forgot write on the code that part, but this doesn't change the error. I tried to do some test and What I saw was that when I generate the exam for the first time it's work great, after that when I try to generate it sent me this error: &quot; The remote server Machine does not exists or is unavailable&quot; but if I leave open the first exam that I generate , the code open a new word document, &quot;Document2&quot; but write the new exam over the old one &quot;Document1&quot;.
So what I think that is happening is that the system get the first document as the selection and I'm sure that at the end I set all the var as nothing, but still is something wrong that I can't find. Please any idea?

Thank you for your time
Trinitri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top