Hi Doug,
Thanks for providing the much easier method of obtaining the path. I had previously been
using a function I named DetermineDBPath97, which called the ParseFilePath function. Your
method is much simpler!
Tom
Function DetermineDBPath97() As String
' Used to determine the folder that this database is saved in.
' This function relies on the ParseFilePath function shown below.
On Error GoTo ProcError
Dim strFilePath As String
strFilePath = CurrentDb.Name
DetermineDBPath97 = ParseFilePath(strFilePath)
ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
, "Error in DetermineDBPath97 procedure..."
Resume ExitProc
End Function
Function ParseFilePath(FullPathAndFileName As String)
'Given a fully qualified path and filename, ParseFilePath returns only the file path.
On Error GoTo ProcError
Dim i As Integer
Dim LastSlash As Integer
Dim StartOfFileName As Integer
For i = 1 To Len(FullPathAndFileName)
LastSlash = InStr(i, FullPathAndFileName, "\")
If LastSlash > 0 Then
StartOfFileName = LastSlash
End If
If LastSlash = 0 Then
GoTo DoneParsingPath
End If
Next i
DoneParsingPath:
ParseFilePath = Left$(FullPathAndFileName, StartOfFileName - 1)
ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
, "Error in ParseFilePath procedure..."
Resume ExitProc
End Function
________________________________________
The equivalent of CurrentProject.path in Access 97 is:
Left$(CurrentDb().Name, Len(CurrentDb().Name) - Len(Dir(CurrentDb().Name)))
FWIW, have you looked at the code at
http://www.mvps.org/access/api/api0001.htm? It's a little more than just a
code snippet.
--
Doug Steele, Microsoft Access MVP
(No private e-mails, please)
Tom Wickerath said:
Doug,
My sample works fine in Access 2000. It currently does not work when converted to Access
97, because I am using a function that was introduced in Access 2000. My solution uses
CurrentProject.path to cause the common dialog box to default to whatever folder the
database itself is saved to. Since Leojordao just indicated that he is working with
Access 2000, but he needs a solution that is compatible with Access 97, I went ahead and
sent him my sample with the caveat that it won't convert to Access 97 as written.
I suspect that the API code that you pointed Leojordao to will work fine in Access 97 too.
The sample that I sent him is more than just a code snippet to invoke a common dialog. As
I indicated last night, I believe it will be fairly easy for me to replace the call to
CurrentProject.path with something that will work in Access 97.
Tom
_________________________________
The API solution I pointed to isn't specific to any version of Access: it
will work in Access 2000.