Hi, I want to automatically update dates in access after printing a document. More specifically, I have 5 templates (Introductory letters, Thank you letters, etc.) to mail merge from word. I have a combo box to choose from these 5 templates, and a button in which when clicked, will print the document. I want to record the date after printing each document.
Below is my code:
Code:
Option Compare Database
Public Function CreateWordLetter(strDocPath As String)
'if no path is passed to function, exit
If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If
Dim dbs As Database
Dim objWord As Object
Dim PrintResponse
Set dbs = CurrentDb
'create reference to Word Object
Set objWord = CreateObject("Word.Application")
'Word Object is created - now let's fill it with data
With objWord
.Visible = True
.Documents.Open (strDocPath)
'move to each bookmark, and insert correct text.
.ActiveDocument.Bookmarks("firstname").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!strMomFirstName))
On Error Resume Next
.ActiveDocument.Bookmarks("address").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!UpdatedMomAddress))
On Error Resume Next
.ActiveDocument.Bookmarks("city").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!UpdatedMomCity))
On Error Resume Next
.ActiveDocument.Bookmarks("state").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!UpdatedMomState))
On Error Resume Next
.ActiveDocument.Bookmarks("zip").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!UpdatedMomZip))
On Error Resume Next
.ActiveDocument.Bookmarks("firstname2").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!strMomFirstName))
On Error Resume Next
.ActiveDocument.Bookmarks("lastname").Select
.Selection.Text = (CStr(Forms!MailMerge_Jun6!strMomLastName))
On Error Resume Next
End With
'find out if the user would like to print the document at this time.
PrintResponse = MsgBox("Print this document?", vbYesNo)
If PrintResponse = vbYes Then
objWord.ActiveDocument.PrintOut Background:=False
End If
'release all objects
Set objWord = Nothing
Set dbs = Nothing
End Function
Private Sub cbxTemplate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub cmdMailMerge_Click()
If Not Len(cbxTemplate.Value) = 0 Then
CreateWordLetter (cbxTemplate.Value)
Else
MsgBox "Select Mail Merge process"
End If
End Sub
Thank you so much,
Meo