E
Edward F
I am using ADO to retrieve data but it overwrites with ADO data
This is a sample of the code am using it is located at
http://support.microsoft.com/kb/q261999/
It works fine but it overwrites any previous text or formating in the
document. I would like to keep my formating and text with the ADO data.
Option Explicit
Const sFileName = "C:\Program Files\Microsoft Visual Studio\VB98\nwind.mdb"
Private Sub Command1_Click()
' Declare our variables
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim sTemp As String
' Create an instance of Word
Set oWord = CreateObject("Word.Application")
' Show Word to the user
oWord.Visible = True
' Add a new, blank document
Set oDoc = oWord.Documents.Add
' Get the current document's range object
Set oRange = oDoc.Range
' Create a new ADO connection
Set oConn = CreateObject("ADODB.Connection")
' Open our connect
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sFileName & ";Persist Security Info=False"
' Execute a SQL statement to retrieve the information
Set oRS = oConn.Execute( _
"SELECT CustomerID, CompanyName, ContactName FROM Customers")
' Use GetString to return the recordset as a string
sTemp = oRS.GetString(adClipString, -1, vbTab)
' Insert a heading on the string
sTemp = "Customer ID" & vbTab & "Company Name" & _
vbTab & "Contact Name" & vbCrLf & sTemp
' Insert the data into the Word document
oRange.Text = sTemp
' Convert the text to a table and format the table
oRange.ConvertToTable vbTab, , , , wdTableFormatColorful2
End Sub
Edward F
tolu10(removethis)@hotmail.com
This is a sample of the code am using it is located at
http://support.microsoft.com/kb/q261999/
It works fine but it overwrites any previous text or formating in the
document. I would like to keep my formating and text with the ADO data.
Option Explicit
Const sFileName = "C:\Program Files\Microsoft Visual Studio\VB98\nwind.mdb"
Private Sub Command1_Click()
' Declare our variables
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim sTemp As String
' Create an instance of Word
Set oWord = CreateObject("Word.Application")
' Show Word to the user
oWord.Visible = True
' Add a new, blank document
Set oDoc = oWord.Documents.Add
' Get the current document's range object
Set oRange = oDoc.Range
' Create a new ADO connection
Set oConn = CreateObject("ADODB.Connection")
' Open our connect
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sFileName & ";Persist Security Info=False"
' Execute a SQL statement to retrieve the information
Set oRS = oConn.Execute( _
"SELECT CustomerID, CompanyName, ContactName FROM Customers")
' Use GetString to return the recordset as a string
sTemp = oRS.GetString(adClipString, -1, vbTab)
' Insert a heading on the string
sTemp = "Customer ID" & vbTab & "Company Name" & _
vbTab & "Contact Name" & vbCrLf & sTemp
' Insert the data into the Word document
oRange.Text = sTemp
' Convert the text to a table and format the table
oRange.ConvertToTable vbTab, , , , wdTableFormatColorful2
End Sub
Edward F
tolu10(removethis)@hotmail.com