A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Formatting Long Documents
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

I am using ADO to retrieve data but it overwrites with ADO data



 
 
Thread Tools Display Modes
  #1  
Old November 8th, 2004, 10:17 PM
Edward F
external usenet poster
 
Posts: n/a
Default I am using ADO to retrieve data but it overwrites with ADO data

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







  #2  
Old November 8th, 2004, 11:01 PM
Jezebel
external usenet poster
 
Posts: n/a
Default

Answered elsewhere.




"Edward F" Edward wrote in message
...
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









 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2000/2002 - Proper Mail Merge steps for ODBC? Tony_VBACoder Mailmerge 7 September 2nd, 2004 09:21 PM
Problems with converting data held in an Excel spreadsheet to Word mark Gray Mailmerge 6 July 8th, 2004 10:54 AM
Pivot and form retrieve data merlin68 General Discussion 1 July 7th, 2004 09:43 PM
Struggling with MS Query... Alex General Discussion 5 July 6th, 2004 11:46 AM


All times are GMT +1. The time now is 05:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.