Hi
I'm a novice (aka "hopeless case") Access user with a VBA code problem I hope some kind soul can help me with please.
I'm using Access 2002 with Word 2002, and XP Professional 5.1.2600 (Service Pack 3). I'm also using MS Outlook 2007 (which may or may not be relevant). I am using VBA within Access to create a new letter template within my database. The template will then be called from within another part of my database to write and mail merge letters into Word.
The VBA code is supposed to call up Word so I can create the new dot template, but Access simply 'hangs' and Word won't start up (or if already started, the new template won't create/open). This used to work in the past, but I don't know what has been changed in my system that could have caused it to not work now (Outlook 2007? new Service Packs? Office 10/12 conflicts?)
Any help or suggestions very greatfully received (please bear in mind my extreme novice status!). Thanks. This is the code
I'm a novice (aka "hopeless case") Access user with a VBA code problem I hope some kind soul can help me with please.
I'm using Access 2002 with Word 2002, and XP Professional 5.1.2600 (Service Pack 3). I'm also using MS Outlook 2007 (which may or may not be relevant). I am using VBA within Access to create a new letter template within my database. The template will then be called from within another part of my database to write and mail merge letters into Word.
The VBA code is supposed to call up Word so I can create the new dot template, but Access simply 'hangs' and Word won't start up (or if already started, the new template won't create/open). This used to work in the past, but I don't know what has been changed in my system that could have caused it to not work now (Outlook 2007? new Service Packs? Office 10/12 conflicts?)
Any help or suggestions very greatfully received (please bear in mind my extreme novice status!). Thanks. This is the code
Code:
Private Sub BtSave_Click()
On Error GoTo Errhandler
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
varReturn = SysCmd(acSysCmdInitMeter, "Creating New Letter", 100)
varReturn = SysCmd(acSysCmdUpdateMeter, 30)
Me.BtSaverec.Enabled = True
Bt_New.Visible = True
SQLQ = "SELECT [Letters Standard].[REFERENCE], [Letters Standard].[DESCRIPTION], [Letters Standard].[Letter Type] " & _
"FROM [Letters Standard] " & _
"Where ((([Letters Standard].[Letter Type]) = " & SelectLetterType & "))" & _
"ORDER BY [Letters Standard].REFERENCE "
LstLetters.RowSource = SQLQ
varReturn = SysCmd(acSysCmdUpdateMeter, 50)
Select Case Me.Tag
Case 1
Bt_New.Tag = 0
NewDoc = Templatesdirectory & Me.REFERENCE & ".Dot"
Set wd = GetObject(, "word.application")
varReturn = SysCmd(acSysCmdUpdateMeter, 60)
With wd
.Application.Visible = True
.Documents.Add(Templatesdirectory & Me.SelectLetterType.Column(1)).SaveAs FileName:=NewDoc
.ActiveDocument.Application.Activate
.Selection.EndOf wdStory
.Application.WindowState = wdWindowStateMaximize
Set wd = Nothing
End With
End Select
varReturn = SysCmd(acSysCmdUpdateMeter, 80)
Bt_New.Enabled = True
Bt_New.SetFocus
BtSave.Enabled = False
varReturn = SysCmd(acSysCmdUpdateMeter, 100)
varReturn = SysCmd(acSysCmdClearStatus)
Exit Sub
Errhandler:
Select Case Err
Case 5151
'Selected file not found
'Selected file not found
' Response = MsgBox("Unable to find the requested file", vbOKOnly + vbInformation, CompanyName)
' Forms.frmPleaseWait.Label1.Caption = "Processing Error! . . . ."
' Forms.frmPleaseWait.Label2.Caption = "Unable to find the requested Letter. Try closing down and Starting Again. If the problem persists call Bluechip Technical Support."
Set wd = Nothing
' DoCmd.Close acForm, "frmPleaseWait"
Exit Sub
Case 429
'Cannot find word
' MsgBox "The System Will Start Word. Please Repeat Your Last Prceedure "
Set wd = New Word.Application
Resume Next
' Exit Sub
End Select
End Sub