Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error message!

Status
Not open for further replies.

adscrims1

MIS
Oct 15, 2002
11
0
0
CN
Can anyone please help.
I have moved my Access database from one machine to another. All the references in my code are the same.
Here is my code for a command using word. Access cant see the reference in line - Set objWord = New Word.Application
I have tried to set the reference to word but with no joy!

'This sub opens, prints and saves a document. It also populates a bookmark based on a text box in your form
'Dim objects and variables
Dim objWord As Object
Dim strFile As String
Dim strSaveAsFile As String
'Grab the Document name This line changes if database or references are moved!
strFile = "C:\Andy's Work\Risk Assessment Database\Project Work\Temp For Workplace risk Assessment.doc"
'Launch word
Set objWord = New Word.Application
With objWord
'Open the file
.Documents.Open FileName:=Chr(34) & strFile & Chr(34)
'Make it visible
.Visible = True
'Populate a bookmark
.ActiveDocument.Bookmarks.Item("Ref").Range.Text = " " & Me.[Assessment Refference Number] 'this is a textbox
.ActiveDocument.Bookmarks.Item("Ref1").Range.Text = " " & Me.[Combo58] 'this is a textbox
.ActiveDocument.Bookmarks.Item("Ref2").Range.Text = " " & Me.[Department] 'this is a textbox
.ActiveDocument.Bookmarks.Item("Ref3").Range.Text = " " & Me.[Combo14] 'this is a textbox
.ActiveDocument.Bookmarks.Item("Ref4").Range.Text = " " & Me.[Location] 'this is a textbox
.ActiveDocument.Bookmarks.Item("Ref5").Range.Text = " " & Me.[Assessment Date] 'this is a textbox
.Application.Options.PrintBackground = False
.ActiveDocument.PrintOut



strSaveAsFile = Chr(34) & "C:\Andy's Work\Risk Assessment Database\Project Work\RAD Assessment Workplace\" & Me.[Assessment Refference Number] & Chr(34)
.ActiveDocument.SaveAs FileName:=strSaveAsFile
.Quit


End With
Set objWord = Nothing

End Sub

Help me please Im going mad!
Andy
 
You should actually try to see if the Word application is open before creating a new application instance.

Set objWord = GetObject("Word.Application")
If objWord Is Nothing Then
Set objWord = New Word.Application
End If

I'm a little hazy about how you set the references. While in a module design mode did you go to Tools/References and select the PC resident version of the Microsoft Word library? Do any listed references show MISSING?




-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top