Opening Word Problem

DavidRS

Registered User.
Local time
Today, 18:16
Joined
Jan 4, 2005
Messages
43
I have cobbled together some code to open a Word template that is a merge doc associated with a query.

The code has a syntax error and I'm not sure what' wrong:

Private Sub Command0_Click()
Set objword = CreateObject("Word.application")

With objword
.Visible = True

.Documents.Open S:\\Information Services\Records Management\FOI\Letters\TEM-SL1FOIAcknowledgement-v101.dot

End Sub


Anybody any ideas?

Thanks in advance
 
The only help I can give is a copy of what I use myself and it works:

Private Sub Command286_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 ("\\ABC.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))

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
 
What line has the error?

Shouldn't the path string to your file be enclosed in double quotes?

.Documents.Open "S:\\Information Services\Records Management\FOI\Letters\TEM-SL1FOIAcknowledgement-v101.dot"
 

Users who are viewing this thread

Back
Top Bottom