Here is the code:
openrs rs, sSql
if rs.Recordcount <> 0 then
dim strScriptName
dim strFileName
strScriptName = Request.ServerVariables("SCRIPT_NAME")
strScriptPath = server.MapPath(strScriptName)
strFileName = left(strScriptPath, instrrev(strScriptPath, "\")) &
GetParam("hdnReport")
Dim app
Set app = server.CreateObject("Word.Application")
Dim doc
Set doc = server.CreateObject("Word.Document")
Set doc = app.Documents.Open(strFileName, , true)
for each fld in rs.fields
With doc.Content.Find
.ClearFormatting
.Text = "<<" & fld.name & ">>"
.Replacement.ClearFormatting
if isnull(fld.value) then
.Replacement.Text = ""
else
if len(fld.value) > 80 then
.Replacement.Text = left(cstr(fld.value), 80)
else
.Replacement.Text = cstr(fld.value)
end if
end if
.Forward = True
.Wrap = 1
.Execute , , , , , , , , , , 2
End With
next
dim strTempFileName
strTempFileName = replace(replace(replace(replace(now(), "/", ""), "\",
""), " ", ""), ":", "") & ".doc"
strFileName = left(strScriptPath, instrrev(strScriptPath, "\")) &
"TempDocs\" & strTempFileName
doc.SaveAs strFileName
strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
"TempDocs/" & strTempFileName
doc.Close
Set doc = Nothing
app.Quit
Set app = Nothing
"McKirahan" wrote:
> "Victor" <> wrote in message
> news:. ..
> > Hi, guys. We have a very old application that is written in classic ASP.
> > It's sitting on a very old server. I am supposed to do a migration of this
> > app to a new server. I copied all the files to a new server with Windows
> > 2000 Server on it (actually it's a virtual server) and installed SQL
> Server
> > 2000. The application works good, except for one little annoying thing.
> They
> > use an Office Automation in this application. The word document is created
> > based on some template and the values from SQL Server are inserted into
> this
> > document. So, on the old server when you click on the report, it
> > automatically generates a MS Word 2000 document and Opens it, so the user
> > can view it and saves it to a temp directory. On this new server we have
> MS
> > Word 2003 installed. So, when I click on the report, the Word document is
> > created in a Temp directory, BUT... the document itself does not open
> > automatically for a user to view. Can anyone help me with this issue,
> please
> > ? I don't know much about classic ASP or Office automation. I am a SQL
> > Server DBA, with some knowledge of .NET programming. But, I guess, at work
> > you have to do what you have to do. Please, help !!!
> >
> > Thanks,
> >
> > Victor.
>
> Could you post the relevant code?
>
> Basicsally the subset of code referencing "Word.Application"; like:
>
> Const wdWindowStateMaximize = 1
> Set objMSW = CreateObject("Word.Application")
> objMSW.WindowState = wdWindowStateMaximize
> Set objDOC = objMSW.Documents.Open("C:\Temp\my.doc")
>
>
>