jann3891
asked on
MS Access, Browse for Folder and then copy file path into text box
Hello Experts,
I need help in modifying a BrowseFolder Dialog code that I found in http://access.mvps.org/access/api/api0002.htm
I have a text box on the form called zTextBox
also have a button on the form called zBrowseButton with this code on the OnClick event:
Dim strFolderName As String
strFolderName = BrowseFolder("Choose Folder For Import")
If Len(strFolderName) > 0 Then
'Put folder path on text box'
Else
'No folder chosen, or user canceled
End If
Here is what I am trying to do.
1. when I click on the button, I want the dialog box to open at C:\Test folder. (The website has a link to Stephen Lebans' added functionality to open the browse folder at a specific place. But I could not get it to work)
2. after seleting the the folder from the Browse Folder dialog box, I click on OK. I want the network path to populate the zTextBox on the form.
I should mention that I am using MS Access 2003 and I am a novice at programming, so please paste the code so I can copy.
Thank you
I need help in modifying a BrowseFolder Dialog code that I found in http://access.mvps.org/access/api/api0002.htm
I have a text box on the form called zTextBox
also have a button on the form called zBrowseButton with this code on the OnClick event:
Dim strFolderName As String
strFolderName = BrowseFolder("Choose Folder For Import")
If Len(strFolderName) > 0 Then
'Put folder path on text box'
Else
'No folder chosen, or user canceled
End If
Here is what I am trying to do.
1. when I click on the button, I want the dialog box to open at C:\Test folder. (The website has a link to Stephen Lebans' added functionality to open the browse folder at a specific place. But I could not get it to work)
2. after seleting the the folder from the Browse Folder dialog box, I click on OK. I want the network path to populate the zTextBox on the form.
I should mention that I am using MS Access 2003 and I am a novice at programming, so please paste the code so I can copy.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you ping me a bit later ... leaving work now ....
thx.mx
thx.mx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Going on "after seleting the the folder from the Browse Folder dialog box, "
mx
mx
Ha! I misread this completely. No excuse: it's even in the title of the question! — (°v°)
Just sayin' lol
ASKER
That did it. Thank you very much
You are welcome ...
mx
mx
ASKER
This is what I have so far.
It is opening the Browse window, when I select a folder, it is populating my text box.
The only thing I want it to do now is to open on a default location of C:\Test
can you help me with that?
Private Sub zAddLinkButton_Click()
'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With Application.FileDialog(4) '4=msoFileDialogFolderPick
'Allow the selection of multiple file.
.AllowMultiSelect = False
.strInitialDir = "C:\"
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a String that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example simply displays the path in a message box.
Me.zPhotoLink = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
End Sub