Hi people, I am doing some unpaid work for a friend on an Access/VB application they have. Everything worked for 5 years and then suddenly one day they got the following error:
Run-time error '91':
Object varialbe or With block variable not set.
When I click on debug it shows this code as the issue. The asterix line is the issue:
With objWord **objWord.ActiveDocument.SaveAs FileName:=strPath & strDocName, _ FileFormat:=wdFormat** 'CLOSE FILE '.Documents.Close (strPath & strDocName & ".docx") objWord.ActiveDocument.Close 'REOPEN FILE objWord.Documents.Open (strPath & strDocName) 'SET VIEW TO PRINT LAYOUT objWord.ActiveWindow.View.Type = wdPrintView End With
There is far more code than this, but this is the section that errors.
Also objWord has been set earlier in the code as per below:
' CREATE WORD DOCUMENT USING SMEC TEMPLATE (TEMPLATE 1) Private Sub CmdCreateTemplate1_Click() On Error GoTo MergeButton_Err Dim objWord As Word.Application Set objWord = CreateObject("Word.Application") With objWord ' Make the application visible. .Visible = True ' Open the document.
Two questions. Obviously the first is HELP! can someone tell me how to fix it? but secondly how did it happen? I mean no one touches this code, and one day it decides to have a bug? Would it be an update etc?
I have a bit of VB and Access background, but nothing off the top of my head comes to mind. Appreciate anything you can do.
Thanks in advance.