Thanks a lot.
You put me on the right road. I changed the final bit to:
And all is fine.
> Actually, if the doc has spaces in the name or the path, those quotes
> become fairly important. Try it on a few documents in your "c:\my
> documents" folder, or on a file with a space in the name. (Dang long
> file names messing everything up! <grin>)
> Strings don't really have quotes around them by default, unless the
> programmer puts them there. Which is what Roger was (correctly)
> doing. (Good job Roger! Most people miss that!)
> The problem is in how Roger is calling Documents.Open. He should be
> using:
> .Documents.Open(strDoc)
> (Note the dot =before= the statement.)
> Because he's also using "On Error Resume Next", the code isn't
> erroring out, and it's falling through to the objWord.Activate
> statement. So Word pops up, empty, and oops!
> When debugging, the first step is to turn off global error checking
> like "On Error Resume Next" and "DoCmd.SetWarnings False" to see where
> the code is =actually= failing at.
> >You shouldn't need to put quotes around the DocStr variable
> >DocStr = Chr(34) & DocStr & Chr(34)
> >because it was Dimmed as a string. Maybe it thinks that you're trying
> >to open a document called ""c:\docs\filename.doc""
> >try taking that part out and see if it works.
> >> Hi
> >> I am trying to load a word doc, the document name and path is
> >contained in a
> >> field "link"
> >> The code is this:
> >> Private Sub linktext_Click()
> >> Dim DocStr As String
> >> Dim objWord As Word.Application, WordRunning As Boolean
> >> If IsNull(Me.link) = True Then
> >> MsgBox "No document to go to", , "No Doc"
> >> Exit Sub
> >> End If
> >> DocStr = Me.link
> >> DocStr = Chr(34) & DocStr & Chr(34)
> >> 'Check to see if word is running
> >> ' Needed for error trapping.
> >> On Error Resume Next
> >> ' Establish communication with Word
> >> ' Clear the error variable.
> >> Err.Clear
> >> ' Check to see whether Word 97 is running.
> >> Set objWord = GetObject(, "Word.Application.8")
> >> If Err.Number <> 0 Then
> >> WordRunning = False
> >> Else
> >> WordRunning = True
> >> End If
> >> ' Reset the error variable.
> >> Err.Clear
> >> If WordRunning = True Then
> >> Set objWord = GetObject("Word.Application")
> >> Else
> >> Set objWord = CreateObject("Word.Application")
> >> End If
> >> With objWord
> >> Documents.Open (DocStr)
> >> objWord.Activate
> >> End With
> >> End Sub
> >> I just can't get word to work. It is fine if a put a real string in
> >> Documents.Open("c:\docs\filename.doc")
> ------
> Please Post Any Replies To This Message Back To the Newsgroup.
> There are "Lurkers" around who can benefit by our exchange!