Insert fields from ACCESS into OPen Office writer

D

DRBE

I have used the code below to insert fields from my Access Tables into a Word
Documet. (eg take "surname" field from "clients" table and insert it into
apprtoptiate place.) Only 1 record needs to be exported eg doing appointment
letter for the client I have just added to the database.
Ideally I would like to be able to save the resultant document as a pdf.
rather than use additional add on software, I thought it might be useful to
use OPenOffice instead.

Does anyone know how to do a similar script to insert fields into a
OPenOffice Writer document, save it as pdf, and then attach into an email.

Thanks in advance for any advice.

kind regards
Bruce

'------------------------------------------------------------------------
Public Sub PrintLetter(vID As Long, vFilename As String)

'Print personalised letter using MS Word
'Entry (vID) holds unique ID of record to be printed
' (vFilename) holds pathname of document to be printed

'Ensure that these references are active-
'Microsoft DAO 3.6 Object Library
'Microsoft Word xx.0 Object Library (xx = your version of Word)

Dim objWord As Word.Application
Dim rst As Recordset

On Error GoTo ErrorCode

'Start MS Word and open specified document
Set objWord = New Word.Application
objWord.Documents.Add vFilename
objWord.ScreenUpdating = False

'Fetch data for specified record from table
Set rst = CurrentDb.OpenRecordset("SELECT * " _
& "FROM tblMembers WHERE ID = " & vID)
ReplaceText objWord, "[FN]", Nz(rst!FirstName)

'add other fields here, as reqd
rst.Close
Set rst = Nothing

objWord.ActiveDocument.Saved = True
objWord.ScreenUpdating = True

objWord.Visible = True
Set objWord = Nothing
Exit Sub

ErrorCode:
objWord.Quit
MsgBox Err.Description

End Su
'--------------------------------------------------------------------------------
Public Sub ReplaceText(obj As Word.Application, vSource As String,
vDest As String)

'Replace all occurences of vSource with vDest in Word doc

obj.ActiveDocument.Content.Find.Execute FindText:=vSource, _
ReplaceWith:=vDest, Format:=True, _
Replace:=wdReplaceAll

End Su
'--------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top