I use the clean up as following ( found this the hard way)
myDoc.Close
objWord.Quit
Set myDoc = Nothing
Set objWord = Nothing
-----Original Message-----
From: Rudy Kurniadi [mailto:RKurniadi@c...]
Sent: Tuesday, August 28, 2001 4:47 AM
To: professional vb
Subject: [pro_vb] RE: Update Word from VB 6.0
Hi Eva, thanks for your code. Talk about coincidence. I was just looking
for a way to generate a word doc with ASP, when I stumbled onto your
posting.
I have modified your code to work on ASP. Everything seemed to work
fine. I managed to generate the word doc with all the bookmarks filled
in. However, when I looked at Task Manager, after running the code, I
could see three instances of winword remained there. When I ran the code
again, I ended up with 6 instances of winword in memory.
What have I done wrong? can anyone identify the fault?
I apologise if this is the wrong list to ask about ASP, but I thought I
post my question here since I got the VB code originally from this list.
Here is my code:
----------------------------
<%
'-- GET DATA --
' get record id
id = Request.QueryString("id")
If id = "" Or IsEmpty(id) Or Not IsNumeric(id) Then
id = 0
End If
If id > 0 Then
' open database connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("Test.mdb")
' open recordset
SQL = "SELECT ProjectName, SiteURL, Company, ContactName, Address1
AS Address, City, State, Postcode, State, Country, Phone, Fax" & _
" FROM Client_Project_Contact WHERE ProjectID = " & id
Set RS_Project = Conn.Execute(SQL)
If Not (RS_Project.EOF And RS_Project.BOF) Then
'-- CREATE WORD DOCUMENT --
Set objWord = Server.CreateObject("Word.Application")
'objWord.Visible = True
If objWord.PrintPreview = True Then ' if existing Word doc is in
Preview mode then close it
objWord.PrintPreview = False
End If
' get template
strTemplate = Server.MapPath("KeyframeApproval.dot")
objWord.Documents.Add strTemplate
Set objDoc = objWord.ActiveDocument
objDoc.Activate
strFile = Server.MapPath("KeyframeApproval_" &
RS_Project("ProjectName"))
'Application.DefaultSaveFormat = "" ' default extension ".doc"
objDoc.SaveAs strFile
'-- FILL IN DATA --
' Must create bookmark on word template with the same name as the
record fields
intBkmrkCount = 1
' Loop thru the bookmarks on the document and find corresponding
action
While intBkmrkCount <= objDoc.Bookmarks.Count
lBkmIndx = ""
MyBkmrk = objDoc.Bookmarks(intBkmrkCount)
Set lRngInsertHere = objDoc.Bookmarks(MyBkmrk).Range
' check if bookmark has an index and if it does - separate name
and index
If IsNumeric(Right(MyBkmrk,1)) Then
MyBkmrk = Left(MyBkmrk,Len(MyBkmrk)-1)
End If
lRngInsertHere.Text = lRngInsertHere.Text &
CStr(RS_Project(MyBkmrk))
intBkmrkCount = intBkmrkCount + 1
WEnd
objDoc.Save
' destroy objects
objDoc.Close
Set objDoc = Nothing
Set objWord = Nothing
End If
' destroy objects
RS_Project.Close
Set RS_Project = Nothing
Conn.Close
Set Conn = Nothing
End If
%>