Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

vbscript write data from the database in word

$
0
0

I have this code and it displays the query results on the pop up notifier. But I would like to write the results to a word document on my C drive. In the word document I inserted the DocVariable field called "table1" .

Is there a way to place the values on something like a table into the word doc?



Call Main()
Sub Main()
  Dim connect, rs
  Set connect = CreateObject("ADODB.Connection")
  Call connect.Open("DSN=PostgreSQL35W;UID=postgres;PWD=xxx")
  If Err.Number <> 0 Then
    Call WScript.Echo(Err.Number)
    Call WScript.Echo(Err.Source)
    Call WScript.Echo(Err.Description)
    WScript.Quit(0)
  End If

  Set rs = connect.Execute("SELECT * FROM tbl_test01")
  If Err.Number <> 0 Then
    Call WScript.Echo(Err.Number)
    Call WScript.Echo(Err.Source)
    Call WScript.Echo(Err.Description)
    WScript.Quit(0)
  End If
  If rs.EOF Then
    rs.close
    Set rs = Nothing
    Call WScript.Echo("NA")
    WScript.Quit(0)
  End If
  Do While Not rs.EOF
    Call WScript.Echo(rs("id").value & "::" & rs("name").value) 
    rs.Movenext
  Loop
  rs.close
  Set rs = Nothing

  connect.Close
  Set connect = Nothing
End Sub


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>