PDA

View Full Version : import into table problem



gibbo1715
08-30-2006, 09:50 AM
All

im using the code below to import from an access database into a table in word, my problem is I have three fields in my database but i want 6 columns in my table, can anyone tell me how to also insert 3 blank cells at the end of each row please

thanks

gibbo

Dim new_field As ADODB.Field
Dim txt As String
Dim new_range As Word.Range
Dim ws As Word.Application
Dim doc As Word.Document
Set ws = New Word.Application
Set doc = ws.Documents.Open("C:\Documents and Settings\Gibbo\Desktop\Test.doc")
Call CheckConnection
' Select all of the records in the table.
Set rs = con.Execute("SELECT URN, Relevance, Where_Stored FROM Test")
' Get the Recordset's data as a single string
' with vbTab between fields and vbCrLf between rows.
txt = rs.GetString(adClipString, , vbTab, Chr(13), "No Value")
txt = Replace(txt, vbCrLf, " ")
' Close the Recordset and Connection.
rs.Close
con.Close

With doc
' Make a Range at the end of the Word document.
Set new_range = .Range
new_range.ParagraphFormat.Alignment = wdAlignParagraphCenter
new_range.Font.Size = 10
new_range.Collapse wdCollapseEnd
' Insert the text and convert it to a table.
new_range.InsertAfter txt
new_range.ConvertToTable vbTab
new_range.Tables(1).Columns(1).Width = 50
new_range.Tables(1).Columns(2).Width = 75
new_range.Tables(1).Columns(3).Width = 130
new_range.Tables(1).Columns(4).Width = 20
new_range.Tables(1).Columns(5).Width = 55
new_range.Tables(1).Columns(6).Width = 55
new_range.Tables(1).Rows.Height = 40
new_range.Tables(1).AutoFitBehavior wdAutoFitFixed 'wdAutoFitWindow wdAutoFitContent
' Add a blank line.
Set new_range = doc.Range
new_range.Collapse wdCollapseEnd
new_range.InsertParagraph
new_range.ParagraphFormat.Alignment = wdAlignParagraphCenter
new_range.Collapse wdCollapseEnd
End With
ws.Visible = True
Set ws = Nothing
Set doc = Nothing
Exit Sub