Path - Gordon, thx in advance if you pick up this one

C

C''''est_moi

Wishful thinking maybe:

I need a command that would say:

if path is "http:\xxxxx", then

Reason being that I have the same forms on 2 different units (network and
web-based application) but would need to give user the possibility of
unprotecting the form if it is savec on one of these units only.

Could not find anything that works.

If you can help, that would so totally great.

Merci.
Carmen
 
J

Jonathan West

C''''est_moi said:
Wishful thinking maybe:

I need a command that would say:

if path is "http:\xxxxx", then

Reason being that I have the same forms on 2 different units (network and
web-based application) but would need to give user the possibility of
unprotecting the form if it is savec on one of these units only.

Could not find anything that works.

If you can help, that would so totally great.

The problem you are encountering arises from the fact that if you open a
Word document from a web location, what happens is that the document is
downloaded to a location in your temporary files folder, and then opened
from there. And so of course the Path property of the document points to the
temporary files folder.

If the presence of the document in the temp folder is enough of an indicator
to be able to distinguish the web-derived form from the other, then you are
sorted. All you need is a routine that will get the temporary files path for
you so you can compare it with the document path.

The temporary files folder is returned by the Windows API command
GetTempPath. if you are not familiar with Windows API commands, they can be
very useful, but you have to be a bit careful with using them. The best way
is to wrap them into little routines that contain all the error handling
that makes them safe to use.

Fortunately, there are lots of VB code snippets available in the web. Almost
everything written for VB6 in this area works perfectly well in VBA, and I
have combined code from two separate sites for the following.

Unfortunately, the GetTempPath returns the path in "short" format. Short
format is a holdever from the days when DOS compatibility with filenames
that could only have 8 characters and a 3-character extension. So when you
use GetTempPath to get the temp files folder, it will give you a string
looking something like this "C:\DOCUME~1\JONATH~1\LOCALS~1\Temp\"

You need to convert it into the long format so it will look like this
"C:\Documents and Settings\Jonathan West\Local Settings\Temp\". Fortunately,
another Windows API function does this - GetLongPathName.

To use both together, place the following code in a separate module in your
project.

Option Explicit

Private Declare Function GetTempPath _
Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetLongPathName Lib "kernel32" Alias _
"GetLongPathNameA" (ByVal lpszShortPath As String, _
ByVal lpszLongPath As String, ByVal cchBuffer As Long) _
As Long

Private Const MAX_PATH As Long = 260

Public Function GetSystemTempPath() As String

Dim sBuffer As String
Dim sShortPath As String
Dim iLen As Long

sBuffer = Space$(MAX_PATH)
iLen = GetTempPath(MAX_PATH, sBuffer)
If iLen > 0 Then
sShortPath = Left$(sBuffer, iLen)
'sShortPath now contains the temp file path in short format.
'We now need to make it a long path

sBuffer = String$(MAX_PATH, 0)
iLen = GetLongPathName(sShortPath, sBuffer, Len(sBuffer))
If iLen > 0 And Err.Number = 0 Then
GetSystemTempPath = Left$(sBuffer, iLen)
Else
GetSystemTempPath = sShortPath
End If
Else
'failed to get value out of GetTempPath
'return null string
GetSystemTempPath = ""
End If
End Function


You now have a function GetSystemTempPath which can be called from anywhere,
and can be compared with the path property of your document. There is one
small wrinkle, and that is that the Path property doesn't put a / character
on the end, while the GetSystemTempPath functioin does. But I'm sure you can
handle that.
 
C

C''''est_moi

Thank you Jonathan. I hadn't realized how complicated that was. I though
there would be some sort of if "ActiveDocument.path" is or isnt "xxx", then.
I guess that goes to show how much I still have to learn. I will look at your
codes and run some tests to see how it works. Thx very much for your thorough
explanation.
Carmen
 

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