CODE: get current dir of MDB file

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
 
M

Marshall Barton

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
 

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