473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get Directory of Current DB

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
9 27545
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
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
"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
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
Nov 13 '05 #5
strDB = CurrentDb.Name
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
Nov 13 '05 #6
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Dan Nash | last post by:
Hi guys I have a page that is *supposed* to list the directories on the server. Here's the code... folderspec = server.MapPath("./images/") set fso =...
3
by: Daniel | last post by:
How do you get the current directory of the actual .exe file (not the file name but the directory it is in) ? These do not work: System.IO.Directory.GetCurrentDirectory() - returns system...
11
by: kk | last post by:
Can any function tell the compiled program executing path? after using the program to open a file from MFC dialog box, the path changes. thks in advance.
4
by: First Tiger | last post by:
Is there a default function or global variable that will allow me to derive the location of my install? I'm trying to store my system settings file from a persistent location. I know that I can set...
3
by: Progman | last post by:
I use Visual Studio 2005 When I run msgbox Curdir(), I get the visual studio directory. This problem seems to be only in the VB part. In the ASP, we use ~/etc... to access files. Why I...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
3
by: Chris Mellon | last post by:
This appears to be a change in behavior from Python 2.4 to Python 2.5, which I can't find documented anywhere. It may be windows only, or related to Windows behavior. In 2.4, the current...
11
by: greg | last post by:
Hi all, Is there a way to get the current theme name at design time? I'm trying to write a custom control for which I need to use images from the current theme. I have asigned a theme to the...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
2
by: Kakkanattu | last post by:
Hi, In desktop application, we use different ways to get the current execution directory. I. AppDomain.CurrentDomain.BaseDirectory II. Environment.CurrentDirectory...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.