I have created aweb application in ASP.NET 2.0 with VB.NET (VS2005) and SQL Server 2005. I have Word 2003 templates that must be filled through automation on the client-side (VBScript) - each user's location has indvidualized templates. I was hoping to be able to fill the Word doc from either a datagrid or gridview which is made up of a single row. I have a button on the page with the datagrid/gridview that triggers the VBScript, opening the bookmarked Word template. My probem is how do I read each cell from the datagrid/gridview.
The relevant code for a DataGrid is:
<form id="form1" runat="server">
<div>
<asp:datagrid id="DataGrid1" runat="server" GridLines="Vertical" CellPadding="3" BackColor="White"
BorderColor="#999999" BorderWidth="1px" BorderStyle="None" Width="100%" Height="100%" Font-Size="X-Small"
Font-Names="Verdana">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></Sele
ctedItemSt
yle>
<AlternatingItemStyle BackColor="Gainsboro"></Al
ternatingI
temStyle>
<ItemStyle BorderWidth="2px" ForeColor="Black" BorderStyle="Solid" BorderColor="Black" BackColor="#EEEEEE"></Item
Style>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" BorderWidth="2px" ForeColor="White" BorderStyle="Solid"
BorderColor="Black" BackColor="#000084"></Head
erStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></Foot
erStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></Page
rStyle>
</asp:datagrid>
<asp:TextBox ID="WPAID" runat="server" Text="-1391708654"></asp:T
extBox>
<asp:Button id="Button1" usesubmitbehavior="true" Text="Print WPA" OnClientClick="FillWPA()" runat="server" />
</div>
</form>
<script type="text/vbscript">
function FillWPA()
Dim oWord, oDoc, oConn, sCommand, sReader, oGridItem
Set oWord = CreateObject("Word.Applica
tion")
Set oDoc = oWord.Documents.Open("C:\N
M_Works_Al
l\HSD\Temp
lates\DWP_
005.dot", , False)
oWord.Visible = true
oDoc.FormFields("Date").re
sult = document.form1("DataGrid1"
).Item.Row
s(0).Cells
(2).Value
oDoc.FormFields("Geo").res
ult = document.form1("DataGrid1"
).Item.Row
s(0).Cells
(3).Value
oDoc.FormFields("Adm").res
ult = document.form1("DataGrid1"
).Item.Row
s(0).Cells
(4).Value
.
.
.
oDoc.FormFields("Edu").res
ult = document.form1("DataGrid1"
).Item.Row
s(0).Cells
(100).Valu
e
oDoc.SaveAs "C:\NM_Works\Documents\WPA
_Test.doc"
I get an error: Microsoft VBScript runtime error: Object required: 'document.form1(...)'
end function
</script>