sashapixie
Board Regular
- Joined
- Aug 29, 2013
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hello There
This is probably the third time I have attempted this process and it fails every time.
I have the following code within a button on my form in access
Private Sub Command283_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim fld As Word.FormField
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Tender Single Record Information Client Details")
rs.MoveFirst
'Open Word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
'Print Tender Letter
TenderLetter = "H:\ESTIMATING - 4000\Tender Letter2.docx"
Set wrdDoc = wrdApp.Documents.Open(TenderLetter)
For Each fld In wrdDoc.FormFields
fld.Result = rs.Fields(fld.Name).Value
Next fld
Set wrdDoc = Nothing
rs.MoveNext
Wend
Set fld = Nothing
Set wrdApp = Nothing
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
I have fields set in a word document called Tender Letter2 and a query call Tender Single Record Information Client Details where the field names match those in the word template.
I can create bookmarks to merge singular information from a record into word no problem, this is not using field forms and does not refer to a query.
I have one record which has many clients so I have created the query to produce the addresses of each client, I need these to merge with the one singular document to create more than one letter.
I hope this makes sense.
Any help would be appreciated.
Thanks
This is probably the third time I have attempted this process and it fails every time.
I have the following code within a button on my form in access
Private Sub Command283_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim fld As Word.FormField
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Tender Single Record Information Client Details")
rs.MoveFirst
'Open Word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
'Print Tender Letter
TenderLetter = "H:\ESTIMATING - 4000\Tender Letter2.docx"
Set wrdDoc = wrdApp.Documents.Open(TenderLetter)
For Each fld In wrdDoc.FormFields
fld.Result = rs.Fields(fld.Name).Value
Next fld
Set wrdDoc = Nothing
rs.MoveNext
Wend
Set fld = Nothing
Set wrdApp = Nothing
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
I have fields set in a word document called Tender Letter2 and a query call Tender Single Record Information Client Details where the field names match those in the word template.
I can create bookmarks to merge singular information from a record into word no problem, this is not using field forms and does not refer to a query.
I have one record which has many clients so I have created the query to produce the addresses of each client, I need these to merge with the one singular document to create more than one letter.
I hope this makes sense.
Any help would be appreciated.
Thanks