Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Current Path name 1

Status
Not open for further replies.

LMBag

Technical User
Mar 27, 2003
11
MX
I have looked for this every where can't seem to be able to find it.

I want to get the path name of the current directory that the database is open in. So for example say the file is open in some directory C:\Quotes\stuff , I want to be able to return this as a string. I know it must be possible, but am at a loss.

Any help would be great.

(Oh, I'm using Access 97 by the way.)
 
Have a look to Dir into the Access 97 help.

Im
 
Sorry, wrong answer, it is:
Dim a as string
a =CurDir(CurrentDb.Name)

There you are!

im

 
Cheers im,

I knew it couldn't be that hard, I think I'm just having a thick day.

 
Sorry to disappoint you, but it returns the current directory, not the directory your database is located in...
The method may work if you open the database through the Open dialog, but will fail if it is opened from a shortcut or through code...
Moreover, if you use ChDir in your code, the statement will return that directory...


I made this a few years ago and I'm still using it:

Function DetectFolder()
'===============================================
'detect folder of the current database
'to check for the existence of the ini file
Dim i As Integer
For i = Len(CurrentDb.Name) To 1 Step -1
If Mid(CurrentDb.Name, i, 1) = "\" Then
DetectFolder = Left(CurrentDb.Name, i)
Exit For
End If
Next
'================================================
End Function

For ADO, change CurrentDb.Name with CurrentProject.FullName

Good luck,

[pipe]
Daniel Vlas
Systems Consultant

 
Hi there dan and im,

Yeah I thought im's suggestion worked, however when I implemented it properly in my working programme, it just returned the Network drive I was working in (J:\).

I have a problem though, I pasted dan's code above and tried that, but it gave me a compile error and said it expected an array, and highlighted the Mid bit. I'm confused, to what it wants here. Sorry to be a burden but if you could help I'd really appreciate it.

Cheers
LB.
 
Sorry, but that still didn't work, I don't think that was the problem as I work with DAO, and it didn't reckonise
CurrentProject.FullName at all.

No, it's something with the Mid function, no idea what mind you. It wants an array. Your code has given me some ideas though.

By the way thanks for the prompt replies.

LB


 
Right then, I've figured it out. Dan, your bit of code gave me an idea.

I used this bit of code in a module where Path is called in so that Path = CurrentDB.Name .

Function FindCurrentFolder(Path As String)

Dim TknNumb As Integer
Dim StrLen As Integer
Dim PathLength As Integer
Dim OriginalPath As String

OriginalPath = Path
PathLength = Len(Path)
TknNumb = 1

Do Until TknNumb = 0
TknNumb = InStr(Path, "\")
StrLen = Len(Path)
Path = Right(Path, StrLen - TknNumb)
Loop

FindCurrentFolder = Left(OriginalPath, PathLength - StrLen)

End Function



This seems to do the trick.

Any thoughts on this, I would be interested to hear your views, or if you have found out the problem with your code.

Thanks for your help.

LB
 
Try this, it works in Access2000 and XP

dim path
path=currentdb.name

This gives you the path and the filename.

If you want just the filename then use this.
dim myfile
myfile=currentproject.name

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top