Classic ASP question. Urgent !!!

V

Victor

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.
 
M

McKirahan

Victor said:
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")
 
V

VictorV

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
 
M

McKirahan

[snip]
Here is the code:
[snip]

Set app = server.CreateObject("Word.Application")
Set doc = server.CreateObject("Word.Document")

You don't need the above line -- it's setting "doc" twice.
Set doc = app.Documents.Open(strFileName, , true)

Did you see this code from my last post?
What happens if you add it?

Oh, this code will close the document so they couldn't see it anyway.
 
V

VictorV

Thanks for your help. It work now, but the problem wasn't code. Because code
worked on that old machine. All I had to do was to add this new intranet site
(the one on a new machine) to Trusted Sites in our group policy.

Thanks again,
Victor.

McKirahan said:
[snip]
Here is the code:
[snip]

Set app = server.CreateObject("Word.Application")
Set doc = server.CreateObject("Word.Document")

You don't need the above line -- it's setting "doc" twice.
Set doc = app.Documents.Open(strFileName, , true)

Did you see this code from my last post?
What happens if you add it?

Oh, this code will close the document so they couldn't see it anyway.
doc.Close
Set doc = Nothing
app.Quit
Set app = Nothing
 
M

McKirahan

VictorV said:
Thanks for your help. It work now, but the problem wasn't code. Because code
worked on that old machine. All I had to do was to add this new intranet site
(the one on a new machine) to Trusted Sites in our group policy.

[SNIP]

I'm glad you got it working.

I found another line of code that seems unnecessary:

strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
"TempDocs/" & strTempFileName

This is the line after
doc.SaveAs strFileName
which has "strFileName" assigned just before it.
 
V

VictorV

I agree. This application is very old, and a lot of code is junky. The vendor
that did this app doesn't exist anymore. I just inherited it and as long as
it still works, I am not touching it. Otherwise, I would have to rewrite it
completely.

Victor.

McKirahan said:
VictorV said:
Thanks for your help. It work now, but the problem wasn't code. Because code
worked on that old machine. All I had to do was to add this new intranet site
(the one on a new machine) to Trusted Sites in our group policy.

[SNIP]

I'm glad you got it working.

I found another line of code that seems unnecessary:

strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
"TempDocs/" & strTempFileName

This is the line after
doc.SaveAs strFileName
which has "strFileName" assigned just before it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top