CODE: get current dir of MDB file

  • Thread starter Thread starter A Man
  • Start date Start date
A

A Man

I will be posting a few short snippets of code. Many of you coders
already know these, but they should benefit other people as well.

Here is code to find the current directory of the MDB file you currently
have open. This is useful for saving output files (like report PDFS,
text files, etc) to the same dir as your MDB file.

It returns the current directory with a trailing backslash.

Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String

strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)

CurrentDBDir = Left(strDBPath, Len(strDBPath) - Len(strDBFile))

End Function
 
A said:
I will be posting a few short snippets of code. Many of you coders
already know these, but they should benefit other people as well.

Here is code to find the current directory of the MDB file you currently
have open. This is useful for saving output files (like report PDFS,
text files, etc) to the same dir as your MDB file.

It returns the current directory with a trailing backslash.

Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String

strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)

CurrentDBDir = Left(strDBPath, Len(strDBPath) - Len(strDBFile))

End Function

In A2002and later, you can use CurrentProject.Path
 
Back
Top