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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 |
Thread Tools | |
Display Modes | |
|
|
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 |