Question : Saving A Word Document opened from a template in MS Access with a specific name

I have a form with two fields, one being an auto-number and the other being test (numerical field).
The user fills out some digits in the Test field, the autonumber is generated. Upon clicking the command button a new instance of an MS word .doc file is opened based on a template.

By default the word document is given the name Document1.

What I would like it to do is create the .doc instance of the .dot file with a specific name. If I could get Access to open/save the word document with the filename being the number value from the Test field within the form, that would be ideal.

Here is my code thus far.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Private Sub Command8_Click()
On Error GoTo Err_Command8_Click
 
Dim oApp As Object
Dim doc As Object
Dim strDocName As String
 
   Set oApp = CreateObject("Word.Application")
   oApp.Visible = True
 
'Set the path to the Oversight Template
strDocName = "L:\Test\Test.dot"
Set doc = oApp.Documents.Add(strDocName)
 
Exit_Command8_Click:
    Exit Sub
 
Err_Command8_Click:
    MsgBox Err.Description
    Resume Exit_Command8_Click
    
End Sub

Answer : Saving A Word Document opened from a template in MS Access with a specific name

After:

      Set doc = oApp.Documents.Add(strDocName)

put:

      doc.SaveAs "c:\folder\subfolder\"Doc" & Me![Test] & ".doc"
Random Solutions  
 
programming4us programming4us