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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New problem linking to MS Word

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
After 12 months of working perfectly including 4 months under newly installed Access 2003 my access 2000 database has suddenly developed a problem with MS Word. I have to admit that my application has been built on trial and error and adapting examples from books & help files as well as kind & generous assistance from members of this forum so when something that has worked suddenly doesn't I need help but simple terms only please.

My code:
Private Sub Command18_Click()
Dim objWord As New Word.Application
stDocName = "house"
stLinkCriteria = "[ref]=" & Forms![buyer]![sellref]
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.add ("c:\letters\otheragent.doc")
.ActiveDocument.Bookmarks("one").Select
.Selection.Text = (CStr(Forms!buyer!corrname))
.ActiveDocument.Bookmarks("two").Select
.Selection.Text = (CStr(Forms!buyer!address))

etc. etc.


I get an error warning "compile error user-defined type not defined".
 
Have you lost your reference to the Word Object library?
 
The error comes on the declaration

Dim objWord As New Word.Application

I find now that if I comment this out and remove the comment from

Set objWord = CreateObject("Word.Application")

then all returns to normal which is good but can anybody explain it to me please (in terms suitable for an idiot).

Many thanks
 
This is to do with 'Early Binding' and 'Late Binding', as far as I recall.

Dim objWord As New Word.Application
Is early binding and for this you need a reference to the Microsoft Word Object Library, which you seem not to have.

Set objWord = CreateObject("Word.Application")
Is late binding (because you have commented out Dim objWord As New Word.Application). For this, you do not need the reference.

I seem to recall that early binding is faster but late binding can be more flexible, for example, if other computers have a different version of Word.

Early Binding means, too, that you use autocompletion, that is, type dot (.) and see what comes up. [dazed]

 
As ever you have been a great help andI really cannot thank you enough.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top