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

Open windows explorer from form 4

Status
Not open for further replies.

dbadmin

Programmer
Jan 3, 2003
147
0
0
US
Hi,

How is it possible to open a Windows Explorer window from a form and select a directory, so that the path of it is displayed in a textbox in the form?

If I am selecting direcory dir1 under C drive, I want the textbox to display C:\dir1\.

Thanks in advance

dbadmin
 
There are two things I'm gathering here. You want to select a directory and have that path returned as a string. You also may want the user to be able to browse for a file and return the entire path including file as a string. Here's the code for the browse dir fuctions - this will return a string with the path of the directory chosen.

'Call this function with something like
'Dim dirPath as String
'dirPath = Pickfolder(c:\)

Function PickFolder(strStartDir) As String
Dim SA As Object, F As Object
Set SA = CreateObject("Shell.Application")
Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not F Is Nothing) Then
PickFolder = F.Items.Item.Path
End If
Set F = Nothing
Set SA = Nothing
End Function

If you want the code for browsing for files, It's availabe on Ben Ohara's website. His user is OharaB if .. I think it's ... He's got some nifty code there for public download. All you need to do is edit it for your needs. Let me know if you can't find his website.

------------------
'How to Keep Your Databases from becoming Overwhelming!' thread181-293590
joshua.peters@attws.com
------------------
 
JPeters, the usual way when you copy'n'paste code from another thread is to give credit...
 
PHV,
When I call this from a command button's on click event
(Access 97), the semicolon is selected with an error
message "Compile error. Expected: list separator or )"

I have
Dim dirPath As String
dirPath = Pickfolder(C:\)

from your original and this thread
Thanks.

John
 
As you are passing a string, enclose the parameter in quotes:

Dim dirPath As String
dirPath = Pickfolder("C:\")


-Gary
 
Gary,
Thanks for that. Could this be expanded to open the Word Open dialog box
(instead of simply saving a pathname) from a command button, like this similar Excel code?

** Begin Excel open dialog box code **

Public Sub cmdExcel_Click()
' credit "vbslammer" - Open Excel worksheet from Access

On Error Resume Next

Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim sht As Excel.Worksheet

Set xl = GetObject(, "Excel.Application")
If err.Number <> 0 Then
Set xl = CreateObject("Excel.Application")
'Else: Set xl = New Excel.Application 'instantiate Excel
End If

xl.Visible = True

' use Excel's built-in open dialog

xl.Dialogs(xlDialogOpen).Show "C:\*.xls"
Set wb = xl.ActiveWorkbook

' put appropriate sheet name/index here.

Set sht = wb.Sheets(1)

' tinker with range properties

With sht
With .Range("E20", "G20")
.Merge
.Value = "Merged Cells"
.HorizontalAlignment = xlHAlignCenter
.Font = "Comic Sans"
.Font.Size = 18
.Font.Bold = True
.Interior.ColorIndex = 27
End With
.Activate
End With

' do more stuff...

End Sub


** End Excel open dialog box code **

Thanks

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top