Solved

specify or browse a folder on a network drive

Posted on 1998-11-22
7
192 Views
Last Modified: 2010-05-03
I would like to specify a folder on a network drive in a visual basic program I am writing. I cannot use a common dialog because the folder may not have any files in it, or I may want to create a new folder on the network drive, with no files in it. I would like to use an interface similar to a common dialog open form or network neighborhood. Any help would be appreciated.
0
Comment
Question by:cliff_martin
7 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1446191
Umm, you *can* use the CommonDialog. It just requires the filename field to be non-blank before the OK button will work. If the user is in an empty directory they can just type X or something and click [OK] and it will return without a problem unless you've got the FileMustExist flag set. If you enable [Cancel] error trap I *think* it will return whatever directory the user has changed to in .FileName

Alternative is to use drive and directory boxes or "roll your own" common dialog box.

M

0
 

Author Comment

by:cliff_martin
ID: 1446192
The common dialog open does not work well. I try to select a directory and end up selecting the directory above it because it I did not click on the whitespace to select directory (if you can follow that, I am impressed). What I am trying to say is that while it does work, it can be confusing to the user. I would be interested in any help in "rolling my own" as you say, though. thanks
0
 
LVL 3

Expert Comment

by:jjbyers
ID: 1446193
Do you want to connect to a network drive or just get a path to a drive already connected?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cliff_martin
ID: 1446194
I want to be able to browse all available network shares, not just mapped drives.
0
 
LVL 3

Accepted Solution

by:
jjbyers earned 30 total points
ID: 1446195
This is the code I use to show the explorer map/disconnect drive dialog box.

Public Const RESOURCETYPE_DISK = &H1

Public Declare Function WNetConnectionDialog Lib "mpr.dll" _
   (ByVal hwnd As Long, ByVal dwType As Long) As Long
   
Public Declare Function WNetDisconnectDialog Lib "mpr.dll" _
   (ByVal hwnd As Long, ByVal dwType As Long) As Long

Public Sub ShowMapDriveDlg(pfrmParent As Form)
'*********************************************************
'* Purpose: Shows the networking map drive letter dialog
'*
'* Input Parameters: pfrmParent - Parent form name
'*
'* Returns: None
'*
'* Called Routines: None
'*********************************************************
  'If the function succeeds, the return value is
  'NO_ERROR (0). If the user cancels out of the
  'dialog box, it is &HFFFFFFFF.
             
  'Passing the form as the hwnd displays the
  'dialog modally to that form.  Pass 0& to
  'make the parent the desktop.
 
  'Setup error trapping
  On Error GoTo MapDrive_Error
 
  Call WNetConnectionDialog(pfrmParent.hwnd, RESOURCETYPE_DISK)
 
  'No Error Exit
  Exit Sub
 
MapDrive_Error:
  'Show Error
  MsgBox "Error in ShowMapDriveDlg of " & Err.Description & " " & Err.Number, vbOKOnly + vbCritical, App.ProductName
End Sub
     
Public Sub ShowDisconnectDriveDlg(pfrmParent As Form)
'*********************************************************
'* Purpose: Shows the networking Disconnect drive dialog
'*
'* Input Parameters: pfrmParent - Parent form name
'*
'* Returns: None
'*
'* Called Routines: None
'*********************************************************
  'If the function succeeds, the return value is
  'NO_ERROR (0). If the user cancels out of the
  'dialog box, it is &HFFFFFFFF.
             
  'Passing the form as the hwnd displays the
  'dialog modally to that form.  Pass 0& to
  'make the parent the desktop.
 
  'Setup error trapping
  On Error GoTo DisconnectDrive_Error
 
  Call WNetDisconnectDialog(pfrmParent.hwnd, RESOURCETYPE_DISK)
 
  'No Error Exit
  Exit Sub
 
DisconnectDrive_Error:
  'Show Error
  MsgBox "Error in ShowDisconnectDriveDlg of " & Err.Description & " " & Err.Number, vbOKOnly + vbCritical, App.ProductName
End Sub

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446196
Bought This Question.
0
 

Expert Comment

by:soyapi
ID: 3335252
You just can map\connect to the other computer, but not on NT Server, I got Access Deny though I supply the right password, still access deny.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 70
Getting warning: You are about to delete 1 row(s) 9 53
Hide vba in gp 7 113
Sub or Function is not defined 6 50
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question