Solved

Access RunTime Error 430

Posted on 2011-02-12
4
759 Views
Last Modified: 2012-05-11
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.

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

Open in new window

0
Comment
Question by:Gwynneth Taylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34879356
:-)
0
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 34879474
You need to set a doc object to the document you just opened.  Bookmarks belong to documents, not to the Word Application object.

Dim doc As Word.Document

...

Set doc = .Documents.Open (etc.)

Then set up your With ... End With statement for the doc object.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34879478
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.
0
 

Author Closing Comment

by:Gwynneth Taylor
ID: 34880196
Thank you - I  am up and running again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question