Make sure that you account for implicit file extensions! I'm guessing
that Word is adding .doc onto your file name during SaveAs.
If so, use Nikos's code with but add the extension
MyFile = myPath & "\" & myFolder & "\" & Me.txtJobNumber & "_ils.doc"
Dir("C:\a") will not detect the file C:\a.doc
HTH,
Kevin
> myFolder = Me![txtRef] & "_" & Me![txtCustomerName]
> myPath = "\\server\LossFiles\"
>
> MyFile = myPath & "\" & myFolder & "\" & Me.txtJobNumber & "_" & "ils"
> If Dir(MyFile)<> "" Then
> AppWord.ActiveDocument.SaveAs MyFile
> Else
> 'code to run if file exists
> End If
> Matt,
>
[quoted text clipped - 33 lines]
>>
>> Matt
Matt - 02 Mar 2005 11:47 GMT
Thanks for your input
I maybe wrong but this idea does not seem to work because we have used this
line first
MyFile = myPath & "\" & myFolder & "\" & Me.txtJobNumber & "_ils.doc"
The ELSE bit is always run because the MyFile variable always holds a value.
I need something that will check for the actual existance of a word doc.
If Dir(MyFile)<> "" Then
AppWord.ActiveDocument.SaveAs MyFile
Else
code to run if file exists
End If
Cheers
Matt
> Make sure that you account for implicit file extensions! I'm guessing
> that Word is adding .doc onto your file name during SaveAs.
[quoted text clipped - 58 lines]
> >>
> >> Matt
Nikos Yannacopoulos - 02 Mar 2005 12:34 GMT
Matt,
I've just noticed that I had the two cases the wrong way around in the
proposed code, sorry about this!
Dir(MyFile) returns the name of the file if the file exists, while it
returns a zero-length string ("") if it does not... so, the code should be:
If Dir(MyFile)<> "" Then
'code to run if file exists
Else
AppWord.ActiveDocument.SaveAs MyFile
End If
The reason you always got the Else part running is most likely because
the filename wasn't assigned correctly to MyFile, so it never found the
file regardless of whether it existed or not. To check the value
assigned to MyFile, precede the If statement with a line:
Debug.Print MyFile
which will print the value of the variable in the immediate window
(Ctrl+G to open if not already open). Chances are you won't see what you
expect!
Nikos
> Thanks for your input
>
[quoted text clipped - 77 lines]
>>>>
>>>>Matt