LookIn with Word Object not working

G

Guest

I try to close a Word file from Access with code:
The filename is saved in a field type hyperlink.
***** collecting name and directory
Do
SlashPlaceInt = 0
SlashPlaceInt = InStr(1, file_name, "\")
If SlashPlaceInt = 0 Then

Exit Do
Else
StringLen = Len(file_name)
StringLen = StringLen - SlashPlaceInt
StringLocation = StringLocation & "\" & Left(file_name,
SlashPlaceInt)
file_name = Right(file_name, StringLen)

End If


Loop
'Start Microsoft Word
Set wordApp = GetObject(, "Word.Application")
'Check wether File exists
Set fs = Application.FileSearch
'Microsoft Office Object Library has to be installed
With fs
*** Here is the LookIn set
.LookIn = StringLocation
.FileName = file_name
When I check in the debugger, the LookIn always is "C:\"
I have copied my code from a different form in the database, there it is
working fine.
The filename is saved in a field type hyperlink. Could the hyperlink type be
the reason and is there a work around?
 
D

Dirk Goldgar

jokobe said:
I try to close a Word file from Access with code:
The filename is saved in a field type hyperlink.
***** collecting name and directory
Do
SlashPlaceInt = 0
SlashPlaceInt = InStr(1, file_name, "\")
If SlashPlaceInt = 0 Then

Exit Do
Else
StringLen = Len(file_name)
StringLen = StringLen - SlashPlaceInt
StringLocation = StringLocation & "\" & Left(file_name,
SlashPlaceInt)
file_name = Right(file_name, StringLen)

End If


Loop
'Start Microsoft Word
Set wordApp = GetObject(, "Word.Application")
'Check wether File exists
Set fs = Application.FileSearch
'Microsoft Office Object Library has to be installed
With fs
*** Here is the LookIn set
.LookIn = StringLocation
.FileName = file_name
When I check in the debugger, the LookIn always is "C:\"
I have copied my code from a different form in the database, there it
is working fine.
The filename is saved in a field type hyperlink. Could the hyperlink
type be the reason and is there a work around?

I'm a bit confused as to what you're really trying to do, but yes, the
fact that the field is a hyperlink makes a difference. The text of a
Hyperlink field contains more than just the path to the file, or the URL
of a website. There are multiple parts to a hyperlink field, separated
by "#" characters, although Access will not normally show you all of
them.

If you want to extract the file path from the hyperlink, you'll need to
start by getting just the address segment of the hyperlink field. So do
something like this:

Dim strFileName As String

strFileName = HyperlinkPart(Me!file_name, acAddress)

Now let the rest of your code work with strFileName instead of
file_name.

But there's something I don't understand. If you just want to find out
if the file exists, why don't you use the Dir() function to do it?
E.g.,

strFileName = HyperlinkPart(Me!file_name, acAddress)

If Len(Dir(strFileName)) > 0 Then
' the file exists
End If

That's way easier than using the FileSearch object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top