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?
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?