I am including the code. I apologize off the bat for the size. The first procedure called from this module is "GETWORDMERGELETTERS". To just recant, this was originally written in Access 97 and has not been touched since converting to Access 2000.
Here goes:
Option Compare Database
Option Explicit
Private myiNumber As Integer 'Used for keeping track of Fiscal Years
Private mycountReport As Integer 'Used for counting reports
Private mycountLetter As Integer 'Used for counting letters/lables
Dim wspJet As Workspace
Dim dbsRecipient As Database
Dim rstRecipient As Recordset
Dim AutoNo
Dim mstAppTitle As String
Dim AutoStr As Integer
Dim FormPath As String
Dim SavePath As String
Dim MyWord As Object, MyDoc As Object
Dim iRetValue As Integer
'(-----------------This declaration is not used------------------)
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function MenuRunLetter(intConstant As Integer)
'(-----------------This function is not used-------------------)
On Error GoTo CommandErrorTrap:
Select Case intConstant
Case 1
countLetter = 1
Case 2
countLetter = 2
Case 3
countLetter = 3
Case 4
countLetter = 4
Case 5
countLetter = 5
Case 6
countLetter = 6
Case 7
countLetter = 7
Case 8
countLetter = 8
Case 9
countLetter = 9
Case 10
countLetter = 10
Case 11
countLetter = 11
Case 12
countLetter = 12
End Select
DoCmd.OpenForm "frmFiscalYearLetter"
Exit Function
CommandErrorTrap:
MsgBox Err.Description, vbCritical, "Error in MenuRunCommand"
Exit Function
End Function
Function fSetAccessCaption() As Boolean
Dim dbs As Database
Const cPropNotExit = 3270
'retrieve old title
Set dbs = CurrentDb
On Error Resume Next
mstAppTitle = dbs.Properties("AppTitle")
'if property doesn't exist
If Err = cPropNotExit Then
fSetAccessCaption = False
Else
dbs.Properties("AppTitle") = "Microsoft Access"
RefreshTitleBar
fSetAccessCaption = True
End If
End Function
Sub sRestoreTitle()
CurrentDb.Properties("AppTitle") = mstAppTitle
RefreshTitleBar
End Sub
Public Property Get iNumber() As Variant
iNumber = myiNumber
End Property
Public Property Let iNumber(ByVal vNewValue As Variant)
myiNumber = vNewValue
End Property
Sub GetWordMergeLetters()
On Error Resume Next ' Defer error trapping.
iRetValue = MsgBox("Do You want to create them?.", _
vbQuestion + vbYesNo, "Letters will be created now.")
If iRetValue = vbNo Then
Exit Sub
End If
' Remove the Application Title
Call fSetAccessCaption
'The GetEnvironment subroutine will get the directories FormPath and SavePath
GetEnvironment
AutoNo = Int((150 * Rnd) + 1)
Select Case countLetter
Case 1
Set MyWord = GetObject(FormPath + "mergeLetter1.doc")
'Set MyWord = GetObject(FormPath + "mrgflrap.doc")
Case 2
Set MyWord = GetObject(FormPath + "mergeLetter2.doc")
'Set MyWord = GetObject(FormPath + "slrap.doc")
Case 3, 8, 12
Set MyWord = GetObject(FormPath + "mergeLetter3.doc")
'Set MyWord = GetObject(FormPath + "arc.doc")
Case 4
Set MyWord = GetObject(FormPath + "mergeLetter4.doc")
'Set MyWord = GetObject(FormPath + "wf-nap.doc")
Case 5
Set MyWord = GetObject(FormPath + "mergeLetter5.doc")
'Set MyWord = GetObject(FormPath + "flrcapr.doc")
Case 6
Set MyWord = GetObject(FormPath + "mergeLetter6.doc")
'Set MyWord = GetObject(FormPath + "slrcapr.doc")
Case 7
Set MyWord = GetObject(FormPath + "mergeLetter7.doc")
'Set MyWord = GetObject(FormPath + "rlnocap.doc")
Case 9
Set MyWord = GetObject(FormPath + "mergeletter9.doc")
'Set MyWord = GetObject(FormPath + "fl-cr.doc")
Case 10
Set MyWord = GetObject(FormPath + "mergeLetter10.doc")
'Set MyWord = GetObject(FormPath + "sl-cr.doc")
Case 11
Set MyWord = GetObject(FormPath + "mergeletter11.doc")
'Set MyWord = GetObject(FormPath + "rl-nc.doc")
End Select
MyWord.mailmerge.Execute
Set MyDoc = GetObject(MyWord.Application.ActiveWindow)
Select Case countLetter
Case 1
MyDoc.saveAs SavePath + AutoNo + "flrap.doc"
'MyDoc.saveAs SavePath + "Letter1.doc"
'MyDoc.PrintOut, , , , 2
'MyWord.saveAs FormPath + AutoNo + "mergeflrap.doc"
MyWord.saveAs FormPath + "mergeLetter1.doc"
Case 2
MyDoc.saveAs SavePath + AutoNo + "Letter2.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter2.doc"
Case 3, 8, 12
MyDoc.saveAs SavePath + AutoNo + "Let3.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter3.doc"
Case 4
MyDoc.saveAs SavePath + AutoNo + "Letter4.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter4.doc"
Case 5
MyDoc.saveAs SavePath + AutoNo + "Let5.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter5.doc"
Case 6
MyDoc.saveAs SavePath + AutoNo + "Let6.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter6.doc"
Case 7
MyDoc.saveAs SavePath + AutoNo + "Let7.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter7.doc"
Case 9
MyDoc.saveAs SavePath + AutoNo + "Let9.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter9.doc"
Case 10
MyDoc.saveAs SavePath + AutoNo + "Let10.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter10.doc"
Case 11
MyDoc.saveAs SavePath + AutoNo + "Let11.doc"
'MyDoc.PrintOut , , , , 2
MyWord.saveAs FormPath + "mergeLetter11.doc"
End Select
MyWord.Application.Quit
Call sRestoreTitle
Set MyWord = Nothing
End Sub
Function MenuRunReport(intConstant As Integer)
'(-----------------This function is not used-------------------)
On Error GoTo CommandErrorTrap:
Select Case intConstant
Case 1
countReport = 1
Case 2
countReport = 2
Case 3
countReport = 3
Case 4
countReport = 4
Case 5
countReport = 5
Case 6
countReport = 6
Case 7
countReport = 7
Case 8
countReport = 8
Case 9
countReport = 9
Case 10
countReport = 10
Case 11
countReport = 11
End Select
DoCmd.OpenForm "frmFiscalYearReport"
Exit Function
CommandErrorTrap:
MsgBox Err.Description, vbCritical, "Error in MenuRunCommand"
Exit Function
End Function
Public Property Get countReport() As Variant
countReport = mycountReport
End Property
Public Property Let countReport(ByVal vNewValue As Variant)
mycountReport = vNewValue
End Property
Public Property Get countLetter() As Variant
countLetter = mycountLetter
End Property
Public Property Let countLetter(ByVal vNewValue As Variant)
mycountLetter = vNewValue
End Property
Sub GetWordMergeLabelsAll()
On Error Resume Next ' Defer error trapping.
iRetValue = MsgBox("Do You want to create them?.", vbQuestion + vbYesNo, "Labels will be created now.")
If iRetValue = vbNo Then
Exit Sub
End If
AutoNo = Int((150 * Rnd) + 1)
' Remove the Application Title
Call fSetAccessCaption
'The GetEnvironment subroutine will get the directories FormPath and SavePath
GetEnvironment
Set MyWord = GetObject(FormPath + "mergeLabelAll.doc")
MyWord.mailmerge.Execute
Set MyDoc = GetObject(MyWord.Application.ActiveWindow)
MyDoc.saveAs SavePath + AutoNo + "LabelAll.doc"
'MyDoc.PrintOut
MyWord.saveAs FormPath + "mergeLabelAll.doc"
MyWord.Application.Quit
' Remove the Application Title
Call sRestoreTitle
Set MyWord = Nothing
End Sub
Private Sub GetEnvironment()
'Returns reference to default workspace.
Set wspJet = DBEngine.Workspaces(0)
'Returns reference to current database.
Set dbsRecipient = CurrentDb()
Set rstRecipient = dbsRecipient.OpenRecordset("tblEnvironment", dbOpenDynaset)
rstRecipient.MoveFirst
FormPath = rstRecipient!FormLocation
SavePath = rstRecipient!Savelocation
'FormPath = "\\NRDCS01\VOL1\DATA\DFM\SHARED\subrecpt\"
'SavePath = "\\NRDCS01\VOL1\DATA\DFM\SHARED\subrecpt\Letters\"
End Sub