VBA Access Mailmerge Template Failing (1 Viewer)

GaryV

New member
Local time
Today, 15:11
Joined
Jul 18, 2009
Messages
2
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

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
 

RuralGuy

AWF VIP
Local time
Today, 08:11
Joined
Jul 2, 2005
Messages
13,826
Maybe if you posted a sample db so we could play with it? I'm feeling real lazy today. Remove any sensitive data of course and Compact and Repair and then Zip it up please.
 

GaryV

New member
Local time
Today, 15:11
Joined
Jul 18, 2009
Messages
2
I'm a bit nervous about posting the whole db (even with sensitive data removed) on a public board RG - could I perhaps send it via private message?
 

Users who are viewing this thread

Top Bottom