Compile Error Help

Gazza111

New member
Local time
Tomorrow, 00:08
Joined
Oct 19, 2004
Messages
8
I use a Command Button in Form "CAR" to open a specific Word Document, input text on the Word Document from the Database, print and close. For some reason today it has decided not to work and I receive the following "Compile Error - Can´t find project or Library". The error seems to be in the line "Dim objWord As Word.Application". Strange thing is, the Database is located on my computer and I receive the error. Computer number 2 also receives the error but for Computer number 3 the Command Button continues to work. Below is a copy of the code:

Private Sub Command202_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application

'Start Microsoft Word 2000.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("\\Rightway5\C\MergeHouseLibertyPolicy.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Salutation2").Select
Selection.Text = (CStr(Forms!CLIENTS!Salutation))
.ActiveDocument.Bookmarks("FirstName").Select
Selection.Text = (CStr(Forms!CLIENTS!FirstNames))
.ActiveDocument.Bookmarks("Surname2").Select
Selection.Text = (CStr(Forms!CLIENTS!Insured))
.ActiveDocument.Bookmarks("Address").Select
Selection.Text = (CStr(Forms!CLIENTS!Address))
.ActiveDocument.Bookmarks("Postcode").Select
Selection.Text = (CStr(Forms!CLIENTS!Postcode))
.ActiveDocument.Bookmarks("Town").Select
Selection.Text = (CStr(Forms!CLIENTS!Town))
.ActiveDocument.Bookmarks("Region").Select
Selection.Text = (CStr(Forms!CLIENTS!Region))
.ActiveDocument.Bookmarks("ClientID").Select
Selection.Text = (CStr(Forms!CLIENTS!ClientID))
.ActiveDocument.Bookmarks("CoverNo").Select
Selection.Text = (CStr(Forms!House!CoverNo))
.ActiveDocument.Bookmarks("Salutation").Select
Selection.Text = (CStr(Forms!CLIENTS!Salutation))
.ActiveDocument.Bookmarks("Surname").Select
Selection.Text = (CStr(Forms!CLIENTS!Insured))
.ActiveDocument.Bookmarks("PolicyNumber").Select
Selection.Text = (CStr(Forms!House!PolicyNumber))
.ActiveDocument.Bookmarks("Administrator").Select
Selection.Text = (CStr(Forms!House!Administrator))

End With

'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next

End If

Exit Sub

End Sub

Please can anyone help?
 
it's almost certainly to do with references. Open the Visual Basic editor window and go to Tools --> References. Look for a reference with MISSING at the start of it and uncheck it (if there are any) then look for references to 'Microsoft Word X.Y Object Library' and if there are any, tick the biggest number (so, faced with 7.4 and 8.0, choose 8.0)
 
Thank you meloncolly

:):) meloncolly, I cannot thank you enough. Although I created the database I am very much a novice and couldn´t have done it without the help of people like yourself. Thank you! gazza111 :) :)
 

Users who are viewing this thread

Back
Top Bottom