Good day.
I have the following function that does this:
- Opens a MS Word Template with form fields.
- Fills the Word form fields with the data from the access form.
This works as expected:
At this stage the Word doc is open and the form fields are filled in.
It is important that I can at this stage finalise (save and close) the word doc, or just keep it open if I wanted to manually add more info later, but I also want to do the following:
Back in my the Access front-end, on another form, I copied the above function, but with different...
However, this second set of fields are OPTIONAL and might or might not be added to the already opened word doc.
So my question is, how to change or add to the above code in order to:
-Check if the Word doc is ALREADY open, then use the 'already-opened' file and add the second set of fields.
At the moment, when I 'submit' the second set of fields, it opens a second instance of the same word template.
Please point me in the right direction to solve this.
Thank you.
Jamie.
I have the following function that does this:
- Opens a MS Word Template with form fields.
- Fills the Word form fields with the data from the access form.
This works as expected:
Code:
Function FillReport()
Dim appword As Word.Application
Dim doc As Word.Document
Dim path As String
On Error Resume Next
Error.Clear
path = "C:\kdb_reports\report.dotx"
Set appword = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set appword = New Word.Application
appword.Visible = True
End If
Set doc = appword.Documents.Open(path, , False)
With doc
.formfields("txt_pt_name1").Result = Me.txt_pt_name1
.formfields("txt_pt_name2").Result = Me.txt_pt_name2
.formfields("txt_dob").Result = Me.txt_dob
.formfields("txt_age").Result = Me.txt_age
.formfields("txt_tel2").Result = Me.txt_tel2
.formfields("txt_tel1").Result = Me.txt_tel1
.formfields("txt_func").Result = Me.txt_func
.formfields("txt_reportdate").Result = Me.txt_reportdate
End With
appword.Visible = True
appword.Activate
appword.ActiveWindow.View.ReadingLayout = False
Set doc = Nothing
Set appword = Nothing
End Function
At this stage the Word doc is open and the form fields are filled in.
It is important that I can at this stage finalise (save and close) the word doc, or just keep it open if I wanted to manually add more info later, but I also want to do the following:
Back in my the Access front-end, on another form, I copied the above function, but with different...
Code:
.formfields("txt_myfield").Result = Me.txt_myfield
However, this second set of fields are OPTIONAL and might or might not be added to the already opened word doc.
So my question is, how to change or add to the above code in order to:
-Check if the Word doc is ALREADY open, then use the 'already-opened' file and add the second set of fields.
At the moment, when I 'submit' the second set of fields, it opens a second instance of the same word template.
Please point me in the right direction to solve this.
Thank you.
Jamie.