Gwynneth Taylor
asked on
Access RunTime Error 430
I have used the attached code with bookmarks to open a word document. Although previously working with no problems I am now getting the following error:
Run time error '430'
Class does not support Automation or does not support expected interface.
Any suggestions please? I have completed system restore and not changed references to my knowledge.
Run time error '430'
Class does not support Automation or does not support expected interface.
Any suggestions please? I have completed system restore and not changed references to my knowledge.
Private Sub cmdLetter_Click()
'Command to export patient information to a word document letter template
On Error GoTo ErrorHandler
Dim wordDoc As Object 'create variable for Word.Document
Dim wordApp As Word.Application 'create variable for Word.Application
Dim wordRange As Object 'Word.Range
create an instance of Word application and a new blank doc
Set wordApp = New Word.Application
Move to each bookmark in the document and insert text from the form.
With wordApp
.Documents.Open Filename:=CurrentProject.path & "\copd discussion.dot"
.ActiveDocument.Bookmarks("PatientTitle").Range.Text = PatientTitle.Value
.ActiveDocument.Bookmarks("PatientInitial").Range.Text = PatientInitial.Value
.ActiveDocument.Bookmarks("PatientSurname").Range.Text = PatientSurname.Value
.ActiveDocument.Bookmarks("PatientAddress1").Range.Text = PatientAddress1.Value
.ActiveDocument.Bookmarks("PatientTown").Range.Text = PatientTown.Value
.ActiveDocument.Bookmarks("PatientCounty").Range.Text = PatientCounty.Value
.ActiveDocument.Bookmarks("PatientPostcode").Range.Text = PatientPostcode.Value
.ActiveDocument.Bookmarks("PatientTitle1").Range.Text = PatientTitle.Value
.ActiveDocument.Bookmarks("PatientSurname2").Range.Text = PatientSurname.Value
.ActiveDocument.PrintPreview
.ActiveDocument.SaveAs Filename:=CurrentProject.path & "\" & PatientID.Value & ".doc"
wordApp.Visible = True
End With
DoEvents
Set wordApp = Nothing
CleanUpAndExit:
Exit Sub
Error Trap
ErrorHandler:
Call MsgBox("Information is missing. Please ensure that all fields are completed to create a letter.")
Resume CleanUpAndExit
End Sub
:-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using ActiveDocument can be chancy, because it might not be the document you think. That is why it is always a good idea to set a doc object as soon as you create or open a Word document, and then work with the doc object.
ASKER
Thank you - I am up and running again.