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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding a network path to a folder

Status
Not open for further replies.

VBdevil

Programmer
Sep 19, 2002
75
IL

I have a button on an access form that, when I press it, opens a folder. My problem is that this folder is on a network drive, so the path to it changes from computer to computer (for example, on one computer this drive is the C: drive, and on another computer this drive is the F: drive). How can I find the path to this folder in different computers?
 
Code below will display the drive name and mapping of any mapped drives. You can examine the ShareName property to determine if it is the correct network path:
Code:
  ' Requires reference to Microsoft Scripting Runtime (SCRRUN.DLL)
  Dim fsoX As Scripting.FileSystemObject
  Dim drvX As Scripting.Drive
  Dim strX As String
  
  Set fsoX = New Scripting.FileSystemObject
  For Each drvX In fsoX.Drives
    If drvX.ShareName <> vbNullString Then
      strX = strX & drvX.RootFolder & " = " & drvX.ShareName & vbCrLf
    End If
  Next drvX
  MsgBox strX

Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
 
Thanks, but it doesn't work on my computer. And I don't think that's the solution I needed.

What I meant was that I have a button that when I press it I want a folder to open. The path to the folder is the same on all computers, but the drive name changes - on one computer it's the C: drive and on another it's the F: drive. For example let's say I want to open folder2 then on one computer the path is C:\Folder1\folder2 and on another it's F:\Folder1\folder2. I need to know how to find out if it's C: or F: or whatever drive.
 
OK, I suppose the drives are local, not network ?

If the file you are looking for is installed at the same time as your app,you could install it where the exe itself is and use app.path (app.path & "/folder1/folder2"

Or make a loop with the whole alphabet !
Save the default path somewhere (ini file, registry ???).
If the file is not there, try somewhere else.
If you find the file, update the default value accordingly.
(Problem if the file is stored on 2 places, you might not work with the right file)

Or you could ask the user to choose the file (using commondialog).

Ok, those are only suggestions (I never done this before, and there might be more suitable solutions)



 
[bold] VBdevil [/bold],

If you want to access that network drive, you should not rely on the mapped adress of it (as you said, it is different from computer to computer).
I suppose you know the path to that network share (let's say "\\MyServer\MyDirectory\MySubdirectory").
You just have to use the fully qualified path and it will work from any computer in that network, no mather if the share is mapped or not.
Does this resolve the problem?

Hope I've been helpful,
Bogdan Muresan.
 
BogdanMBM, I didn't understand what you meant by your answer.

I thought about using app.path as in cbsm's answer, but it doesn't work. I forgot to mention that I'm using VB through Access to write code for an access form. There's no path property for the application object...
 
VBDevil - if you use are using VB in Access, you should use one of the access forums !

I know there is something similar in Access VBA as I used it before.

This is what I found on the help file from access when I was looking for "path":


Path Property


You can use the Path property to determine the location where data is stored for a Microsoft Access project (.adp) or Microsoft Access database (.mdb).

Setting

The Path property is a string expression that is the pathname to the disk location where data is stored for an Access database.

This property is available only by using Visual Basic and is read-only.

Remarks

You can use the Path property to determine the location of information stored through the CurrentProject or CodeProject objects of a project or database.


Please next time post in the appropriate forum !
You have better chances to get en apporpriate answer !
 
So it is an Access application. Yes, there is no app object like in VB (I mean with the same properties).
From what I understood, you want to acces a network folder from your application and you are using a mapped drive that points to the network folder.
If this is the case (if I understand corectly, if not, tell me) I'm thinking to forget about the mapped drive (witch can have different letters on different computers) and just use the full path to that network share (for example "\\ProductionServer\AccessNetworkFolder\").
This will eliminate the problem with mapped drives.
The mapped drives are just, ... lets say, "shortcuts" to your network shared folder. You can easely bypass them using the full path to your network folder.

Hope I've been helpful,
Bogdan Muresan.
 
VBdevil
Check out faq222-2244 for guidance on forum usage. If you're using VBA rather than VB6 then you will do better in one of the VBA forums, forum705 or forum707. Although there are many similarities, there are also many differences and posting in the wrong forum lads to lots of wasted time for you and the other posters. [smile]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
I solved the problem - but thanks for your help.

By the way, I did post the message also in the Access forum...
 
If you posted the same question in two forums, you definitely need to read faq222-2244. Cross posting is generally discouraged unless you refer both questions to be answered in one place

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
My solution was: I used Application.CurrentProject.Path to find the path to my database and then used the left() function to take the first letter, which is the drive name. I was looking for a better solution than that - but this is OK too.

I didn't post this message in two forums - I posted another message in 2 forums, and I did that because I posted it first on one forum and there were no responses, so I thought that maybe the other forum would be more useful.
Didn't mean to cause any duplicate messages - sorry for all the confusion, and thanks for everbody's help...
 
Disclaimer: I am a novice user at the moment.

That being said, I have been put onto a little project which is related to what everyone is discussing here and I believe I have an easier way to approach what everyone wants to do, but I don't know how to implement it via VB6.

There is an ASCII file by the name of: Hosts. Located in the the following path: C:\WINNT\system32\drivers\etc

This file simply keeps track of ip addresses and whatever common name is associated with it.

By editing this file and creating a common name for a network drive and associating it with its IP address, you can directly access it simply by typing its common name on the address bar of Windows Explorer.

My project is to make a little program to directly access this remote location via the network drive's common name and to allow the user to browse that drive without ever having to explicity indicate the drive location via any drop down menus. In other words, this program is designed to be used on any computer on the local network and it will always know how to reach the network drive because it will be explicity stated how to on the Hosts file. The only thing needed would be for the common name to be hard coded into the VB source code.

The little program would still have a tree list box as well as a file list box. It would just be missing a drive list box since there would be no need for it.

Please Advise. Thanks in Advance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top