Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client Side Arrays

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
Hello All,
I hope somebody can help me out here.

How can I create an array using this connection :

Set conn = CreateObject("ADODB.Connection")
conn.open "schoolsasp","schoolsasp","schoolsasp"

SQL = "SELECT * FROM vSchoolDetails ORDER BY EstablishmentName"

If cstr(Param) <> &quot;&quot; And cstr(Data) <> &quot;&quot; Then
sql = sql & &quot; And [&quot; & cstr(Param) & &quot;] = &quot; & cstr(Data)
End If
Set ors = CreateObject(&quot;ADODB.Recordset&quot;)
ors.Open sql, conn, 3, 3


then place the results into VBScript so I can then pick up with :

oApp.Selection.TypeText &quot;The Headteacher &quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;EstablishmentName&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;Address1&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;Address2&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;County&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;PostCode&quot;
oApp.Selection.TypeParagraph


?
at present My connection and SQL is all done within VBScript, but I want that part to take place on the web server.

any help is appreciated

Jamie
 
if I am understanding what you want to do correctly(i.e. EstablishmentName,Address1,Address2,County,PostCode are from the query) then:

oApp.Selection.TypeText &quot;The Headteacher &quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;<%=ors(&quot;EstablishmentName&quot;)%>&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;<%=ors(&quot;Address1&quot;)%>&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;<%=ors(&quot;Address2&quot;)%>&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;<%=ors(&quot;County&quot;)%>&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;<%=ors(&quot;PostCode&quot;)%>&quot;
oApp.Selection.TypeParagraph
 
what I actually need to do is run the query then have a way of :

making the RS = oRS in the VB Script.

is that possible ?

' Convert the recordset to a string.
sTemp = oRS.GetString(2, -1, vbTab) ' 2 = adClipString

' Append the field names to the front of the string.
For Each oField In oRS.Fields
sHead = sHead & oField.Name & vbTab
Next
 
maybe I should post all my code.
it works fine if the users machine has a DSN called schoolsasp.
I want to run the connectoin part on the server.

<%@ Language=VBScript %>
<HTML>
<BODY>
<input type=&quot;button&quot; value=&quot; Back &quot; OnClick=&quot;document.location='./reports.asp';return false;&quot; id=button1 name=button1>

<SCRIPT LANGUAGE=VBScript>
Sub CreateDataDoc(oApp)
' Declare variables.
Dim sSQL, oDoc,oRS,sTemp,sHead,oRange,oField

' Create a new document.
Set oDoc = oApp.Documents.Add
' Create a new recordset.

Set conn = CreateObject(&quot;ADODB.Connection&quot;)
conn.open &quot;schoolsasp&quot;,&quot;schoolsasp&quot;,&quot;schoolsasp&quot;

SQL = &quot;SELECT * FROM vSchoolDetails ORDER BY EstablishmentName&quot;

If cstr(Param) <> &quot;&quot; And cstr(Data) <> &quot;&quot; Then
sql = sql & &quot; And [&quot; & cstr(Param) & &quot;] = &quot; & cstr(Data)
End If
Set ors = CreateObject(&quot;ADODB.Recordset&quot;)
ors.Open sql, conn, 3, 3

' Convert the recordset to a string.
sTemp = oRS.GetString(2, -1, vbTab) ' 2 = adClipString

' Append the field names to the front of the string.
For Each oField In oRS.Fields
sHead = sHead & oField.Name & vbTab
Next

' Strip off the last tab.
sTemp = Mid(sHead, 1, Len(sHead) - 1) & vbCrLf & sTemp

' Get a range object and insert the text into the document.
Set oRange = oDoc.Range
oRange.Text = sTemp

' Convert the text to a table.
oRange.ConvertToTable vbTab
' Save the document to a temp file.
oDoc.SaveAs &quot;C:\labeldata.doc&quot;
' Close the document (no save).
oDoc.Close FALSE

oRS.Close
Conn.Close
set oRS = Nothing
set Conn = Nothing

End Sub


Sub ButtonClick()
Dim oApp
Dim oDoc
Dim oMergedDoc

' Create an instance of Word.
Set oApp = CreateObject(&quot;Word.Application&quot;)

' Create our data file.
CreateDataDoc oApp

' Add a new document.
Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
' Add our fields.
oApp.Selection.TypeText &quot;The Headteacher &quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;EstablishmentName&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;Address1&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;Address2&quot;
oApp.Selection.TypeText &quot;, &quot;
.Fields.Add oApp.Selection.Range, &quot;County&quot;
oApp.Selection.TypeParagraph
.Fields.Add oApp.Selection.Range, &quot;PostCode&quot;
oApp.Selection.TypeParagraph

' Create an autotext entry.
Dim oAutoText
Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add _
(&quot;MyLabelLayout&quot;, oDoc.Content)
oDoc.Content.Delete
.MainDocumentType = 1 ' 1 = wdMailingLabels

' Open the saved data source.
.OpenDataSource &quot;C:\labeldata.doc&quot;


' Create a new document.
Dim label
'label = document.forms.form1.MyType.options[document.forms.form1.MyType.options.selectedIndex].value
label = document.form1.MyType.value
'oApp.MailingLabel.CreateNewDocument &quot;5160&quot;, &quot;&quot;, _
' &quot;MyLabelLayout&quot;, , 4 ' 4 = wdPrinterManualFeed
oApp.MailingLabel.CreateNewDocument label, &quot;&quot;, &quot;MyLabelLayout&quot;, , 4 ' 4 = wdPrinterManualFeed

.Destination = 0 ' 0 = wdSendToNewDocument
' Execute the mail merge.
.Execute

oAutoText.Delete
End With

' Close the mail merge edit document.
oDoc.Close FALSE
' Get the current document.
Set oMergedDoc = oApp.ActiveDocument
' Show Word to the user.
oApp.Visible = True

' Uncomment these lines to save the merged document locally.
'oMergedDoc.SaveAs &quot;C:\test.doc&quot;
'oMergedDoc.Close False
'oApp.Quit False
End Sub
</SCRIPT>

<CENTER>

<FORM name=&quot;form1&quot;>
<td><p CLASS=&quot;norm&quot;>Please Select Label Type<BR></td>
<BR>
<td>
<SELECT CLASS=&quot;inputbox&quot; name=&quot;MyType&quot; size=&quot;1&quot; style=&quot;WIDTH: 152px&quot;>

<OPTION value=&quot;5160&quot; SELECTED>5160 (7 x 3)</OPTION>
<OPTION value=&quot;5162&quot; >5162 (8 x 2)</OPTION>

</SELECT></td></TR>
<INPUT type=button value=&quot;Mail Merge&quot; onclick=&quot;VBScript:ButtonClick&quot; id=button1 name=button1>

</FORM>
</CENTER>
</P>

</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top