L
Lesli
I'm using the following function to perform a merge from Access to a Word
doc, using a query from my database as the datasource for the mail merge.
Public Function PerformMerge(reportName As String, qryName As String,
Optional hideOriginal As Boolean = True)
On Error GoTo ExitError
'Display status to user
SysCmd acSysCmdSetStatus, "Automating Microsoft Word . . ."
DoCmd.Hourglass True
'Declare variables
Dim wApp As New Word.Application
Dim wDoc As Word.Document
Dim wMerge As Word.MailMerge
'Open the word document
Set wDoc = wApp.Documents.Open(getFilePath() & reportName & ".doc", ,
True, False, , , True, , , , , True)
'Modify merge properties to this database, using the query specified.
Set wMerge = wDoc.MailMerge
With wMerge
.OpenDataSource CurrentProject.FullName, , , False, True, False, , ,
True, , , "Query " & qryName
.Execute
End With
'There is no need to view the original merge document, close it without
saving
If hideOriginal Then wDoc.Close wdDoNotSaveChanges
'Make word visible
wApp.Visible = True
ExitNormal:
SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Exit Function
ExitError:
Select Case Err.Number
Case 5631 'No records - merge failed
MsgBox "No Adjudication Orders due" & reportName & ".",
vbExclamation, "No data"
wApp.Quit wdDoNotSaveChanges
Set wApp = Nothing
Case Else
MsgBox Err.Number & " unhandled error " & Err.Description
End Select
Resume ExitNormal
End Function
My database is accessed through a shortcut that uses a .mdw file to open a
..mde file. How do I incorporate the security workgroup and password stuff
into the .OpenDataSource code line?
Thanks,
Lesli
doc, using a query from my database as the datasource for the mail merge.
Public Function PerformMerge(reportName As String, qryName As String,
Optional hideOriginal As Boolean = True)
On Error GoTo ExitError
'Display status to user
SysCmd acSysCmdSetStatus, "Automating Microsoft Word . . ."
DoCmd.Hourglass True
'Declare variables
Dim wApp As New Word.Application
Dim wDoc As Word.Document
Dim wMerge As Word.MailMerge
'Open the word document
Set wDoc = wApp.Documents.Open(getFilePath() & reportName & ".doc", ,
True, False, , , True, , , , , True)
'Modify merge properties to this database, using the query specified.
Set wMerge = wDoc.MailMerge
With wMerge
.OpenDataSource CurrentProject.FullName, , , False, True, False, , ,
True, , , "Query " & qryName
.Execute
End With
'There is no need to view the original merge document, close it without
saving
If hideOriginal Then wDoc.Close wdDoNotSaveChanges
'Make word visible
wApp.Visible = True
ExitNormal:
SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Exit Function
ExitError:
Select Case Err.Number
Case 5631 'No records - merge failed
MsgBox "No Adjudication Orders due" & reportName & ".",
vbExclamation, "No data"
wApp.Quit wdDoNotSaveChanges
Set wApp = Nothing
Case Else
MsgBox Err.Number & " unhandled error " & Err.Description
End Select
Resume ExitNormal
End Function
My database is accessed through a shortcut that uses a .mdw file to open a
..mde file. How do I incorporate the security workgroup and password stuff
into the .OpenDataSource code line?
Thanks,
Lesli