mikewood1980
Registered User.
- Local time
- Today, 15:52
- Joined
- May 14, 2008
- Messages
- 45
Hi
Can anyone help with this...
I've want to write the contents of a table to a word document so that the information appears as a table in the document.
The code below opens a template and writes each row from the table on a different line (fields on the same row are tab separated).
I would like to have this table appear in the word doc as a proper table.
Does anyone have any idea how to do this?
Thanks in advance for your help!
Mike Wood
Can anyone help with this...
I've want to write the contents of a table to a word document so that the information appears as a table in the document.
The code below opens a template and writes each row from the table on a different line (fields on the same row are tab separated).
Code:
Private Sub CreateWordDoc_Click()
Dim dbCurr As Database
Set dbCurr = DBEngine.Workspaces(0).Databases(0)
Dim rsLining As Recordset
Set rsLining = dbCurr.OpenRecordset("tblLining")
Dim objWord As Word.Application
Dim objTable As Word.Table
On Error Resume Next
'Use a running word instance if possible
Set objWord = GetObject(, Word.Application)
'Otherwise use a new instance
If objWord Is Nothing Then
Set objWord = New Word.Application
'If true, Word is not installed.
If objWord Is Nothing Then
MsgBox "Word is not installed on your system"
End If
End If
Set objWord = objWord.Documents.Add("M:\Specific Projects 2008\SI Testing - Pre-Completion\- ALL PCT Report TEMPLATES -\PCT - 6 Positions\Conversions ANC Report Template AB & IP - 6 Positions.dot")
objWord.Activate
objWord.Visible = True
If rsLining.EOF And rsLining.BOF Then
MsgBox ("nothing in the table to tranfer")
Else
rsLining.MoveFirst
Do
With objWord.Selection
.TypeText vbTab
.TypeText rsLining.Fields("intLiningID")
.TypeText vbTab
.TypeText rsLining.Fields("chrOuterBoard")
.TypeParagraph
End With
rsLining.MoveNext
Loop While Not rsLining.EOF
End If
rsLining.close
Set doc = Nothing
Set objWord = Nothing
End Sub
Does anyone have any idea how to do this?
Thanks in advance for your help!
Mike Wood