So I have a database where students record their examination notes.
At the end of their examination I expect them to add important photos to a Word document template called "Continuity Imaging Record" that I have pre-made. The Word document successfully pulls information from the Access database such as Examiner details, Examination date, Case number ect ect using bookmarks. That's not the issue.
The issue is;
When they are nearing the end of the examination, I want them to be able to press a button on the form in Access which will copy the "Continuity Imaging Record" template, pull certain information (mentioned above) BUT THEN save the filename of this new Word document with information from a control located in the access database form. The control is called "FilenameCont" and it usually looks like this..... 12345-2022 JRS Cont Imag Record....
[VBA is not my strength]
I have the following code....
-----------------
Private Sub cmdPrint_Click()
Dim appWord As Word.Application
Dim DOC As Word.Document
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set DOC = appWord.Documents.Open("H:\Abilas 1.16.8\Continuity Imaging Record.docx", , True)
With DOC
.FormFields("flddateexam").Result = Me![Dateofexamination]
.FormFields("fldexaminer").Result = Me![examiner]
.FormFields("fldcasenum").Result = Me![Casenumber]
.Visible = True
.Activate
.SaveAs2 "Test.docx"
End
Set DOC = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End With
End Sub
----------------------------
This code works to my amazement but saves the new Word document filename with Test.docx
I tried replacing this line with the following
.SaveAs2 "Me![FilenameCont].docx"
But then it saves the word document filename with Me![FilenameCont].docx... When I want it to grab the data from [FilenameCont] control and make it the filename. So the filename will be "1234-2022 JRS Cont Imag Record"
Can anyone help??