dvst8
Jun 6th, 2000, 02:42 AM
I posted this in the VB Forum.. but I think it's more applicable to this forum.. hope someone knows:
I have an event handler on a web page, which upon a button click will create an instance of a word application on the server and do some stuff to it.
I'm having trouble getting this to work...
Here is the code that I have, upon button click nothing seems to happen. No errors, no file created...
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript runat=server>
<!--
Sub report_button_onclick
Set ObjWord = CreateObject("Word.Application")
Set doc1 = ObjWord.Documents.Open("c:\temp\report.doc")
ObjWord.Selection.EndKey Unit=wdStory
ObjWord.Selection.Tables.Add Range=ObjWord.Selection.Range, NumRows=1, NumColumns=5
ObjWord.Selection.TypeText Text="First Name"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Last Name"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Phone Number"
ObjWord.Selection.MoveRight UnitwdCell
ObjWord.Selection.TypeText Text="FaxNumber"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Building"
ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
ObjWord.Selection.InsertRows 1
ObjWord.Selection.MoveLeft Unit=wdCharacter, Count1
stmSQL = "SELECT * FROM table1 WHERE Building = 'b2'"
Set oRS = CreateObject("ADODB.Recordset")
'Open the connection.
oRS.Open stmSQL, "DSN=bdata"
oRS.MoveFirst
Do While Not oRS.EOF
fn = oRS("FirstName")
ln = oRS("LastName")
ph = oRS("WorkPhone")
fx = oRS("FaxNumber")
bldg = oRS("Building")
ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
ObjWord.Selection.InsertRows 1
ObjWord.Selection.MoveLeft Unit=wdCharacter, Count=1
ObjWord.Selection.TypeText Text=fn
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=ln
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Textph
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=fx
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=bldg
oRS.MoveNext
Loop
'Close the Recordset object.
oRS.Close
'save the file
doc1.SaveAs FileName="c:\temp\report1.doc"
doc1.Close
ObjWord = Nothing
End Sub
-->
</SCRIPT>
Any ideas why this isn't producing desired results?
I originally wrote this code in VB, and am trying to adapt it to VBScript so that it runs on my webpage...The methods I'm using on the word object may not even be valid.??
Suggestions would be appreciated!
tx
dvst8
I have an event handler on a web page, which upon a button click will create an instance of a word application on the server and do some stuff to it.
I'm having trouble getting this to work...
Here is the code that I have, upon button click nothing seems to happen. No errors, no file created...
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript runat=server>
<!--
Sub report_button_onclick
Set ObjWord = CreateObject("Word.Application")
Set doc1 = ObjWord.Documents.Open("c:\temp\report.doc")
ObjWord.Selection.EndKey Unit=wdStory
ObjWord.Selection.Tables.Add Range=ObjWord.Selection.Range, NumRows=1, NumColumns=5
ObjWord.Selection.TypeText Text="First Name"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Last Name"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Phone Number"
ObjWord.Selection.MoveRight UnitwdCell
ObjWord.Selection.TypeText Text="FaxNumber"
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text="Building"
ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
ObjWord.Selection.InsertRows 1
ObjWord.Selection.MoveLeft Unit=wdCharacter, Count1
stmSQL = "SELECT * FROM table1 WHERE Building = 'b2'"
Set oRS = CreateObject("ADODB.Recordset")
'Open the connection.
oRS.Open stmSQL, "DSN=bdata"
oRS.MoveFirst
Do While Not oRS.EOF
fn = oRS("FirstName")
ln = oRS("LastName")
ph = oRS("WorkPhone")
fx = oRS("FaxNumber")
bldg = oRS("Building")
ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
ObjWord.Selection.InsertRows 1
ObjWord.Selection.MoveLeft Unit=wdCharacter, Count=1
ObjWord.Selection.TypeText Text=fn
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=ln
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Textph
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=fx
ObjWord.Selection.MoveRight Unit=wdCell
ObjWord.Selection.TypeText Text=bldg
oRS.MoveNext
Loop
'Close the Recordset object.
oRS.Close
'save the file
doc1.SaveAs FileName="c:\temp\report1.doc"
doc1.Close
ObjWord = Nothing
End Sub
-->
</SCRIPT>
Any ideas why this isn't producing desired results?
I originally wrote this code in VB, and am trying to adapt it to VBScript so that it runs on my webpage...The methods I'm using on the word object may not even be valid.??
Suggestions would be appreciated!
tx
dvst8