By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Get Directory of Current DB

P: n/a
Is there a way that I would be able to get the current directory of the
database I am working in.

Example: If my database were in "C:\MyDocs\MYDB.mdb" then I would like the
code to return "C:\MyDocs\"

thanks

T Martin
Nov 13 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
T Martin wrote:
Is there a way that I would be able to get the current directory of the
database I am working in.

Example: If my database were in "C:\MyDocs\MYDB.mdb" then I would like the
code to return "C:\MyDocs\"


Function ourPath() As String
Dim cRes As String
Dim nPos As Long
cRes = CurrentDb.Name
nPos = Len(cRes)
Do Until Right(cRes, 1) = "\"
nPos = nPos - 1
cRes = Left(cRes, nPos)
Loop
ourPath = cRes
End Function

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #2

P: n/a
Bas' solution will work for any version of Access.

From Access 2000 onward, you can just use:
Left(CurrentProject.FullName, InstrRev(CurrentProject.FullName, "\"))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bas Cost Budde" <b.*********@heuvelqop.nl> wrote in message
news:cn**********@news2.solcon.nl...
T Martin wrote:
Is there a way that I would be able to get the current directory of the
database I am working in.

Example: If my database were in "C:\MyDocs\MYDB.mdb" then I would like
the
code to return "C:\MyDocs\"


Function ourPath() As String
Dim cRes As String
Dim nPos As Long
cRes = CurrentDb.Name
nPos = Len(cRes)
Do Until Right(cRes, 1) = "\"
nPos = nPos - 1
cRes = Left(cRes, nPos)
Loop
ourPath = cRes
End Function
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea

Nov 13 '05 #3

P: n/a
"T Martin" <ma********@charter.net> wrote:
Is there a way that I would be able to get the current directory of the
database I am working in.

Example: If my database were in "C:\MyDocs\MYDB.mdb" then I would like the
code to return "C:\MyDocs\"

thanks

T Martin

The following will break it down to:

"C:\MyDocs\MYDB.mdb"
"C:\MyDocs\"
"MYDB.mdb"

Function CurrentDBDir() As String

Dim strDBPath As String, strDBFile As String

strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)

CurrentDBDir = strDBPath & vbCrLf & _
Left(strDBPath, Len(strDBPath) - Len(strDBFile)) & vbCrLf &
_
strDBFile

End Function
--
Graham
Nov 13 '05 #4

P: n/a
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
Nov 13 '05 #5

P: n/a
strDB = CurrentDb.Name
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
Nov 13 '05 #6

P: n/a
Johan wrote:
strDB = CurrentDb.Name
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))


Clever! to subtract the filename, as it were. I'll stick that in my toolbox.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #7

P: n/a
Or: CurrentProject.Path

- Steve

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Bas' solution will work for any version of Access.

From Access 2000 onward, you can just use:
Left(CurrentProject.FullName, InstrRev(CurrentProject.FullName, "\"))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Nov 13 '05 #8

P: n/a
Thanks, Steve

Doesn't get much simpler than that!

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Stephen K. Young" <s k y @ stanleyassociates . com> wrote in message
news:30*************@uni-berlin.de...
Or: CurrentProject.Path

Nov 13 '05 #9

P: n/a
Thanks for all the options

"T Martin" <ma********@charter.net> wrote in message
news:CU***********@fe12.lga...
Is there a way that I would be able to get the current directory of the
database I am working in.

Example: If my database were in "C:\MyDocs\MYDB.mdb" then I would like the
code to return "C:\MyDocs\"

thanks

T Martin

Nov 13 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.