browse file function?? help!!

jocelyn_ooi

Registered User.
Local time
Yesterday, 19:42
Joined
Sep 27, 2011
Messages
17
i wanna create a browse file function in my access and i success run the system by following code. But i want let user only can select the file from specific path/location for example in c drives anyone can help me to do so?

Private Sub cmdBrowse_Click()
' Requires reference to Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog

' Not allow user to make multiple selections in dialog box
.AllowMultiSelect = False

' Set the title of the dialog box.
.Title = "Please select one file"

' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "PDF", "*.PDF"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.

If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
Me.txt_support_doc = varFile
Next
Else
MsgBox "Cancel dialog box."
End If
End With
End Sub
 
Use the InitialFileName Property to define the starting path.

I don't know any way to limit the FileBrowse once it is opened but you could test for acceptable paths. Once they have selected the file, parse its path and verify that it included in a list of acceptable paths.
 
how to validate the acceptable path? i not so familiar in ms access..
 
Parse the selected filepath using the Split function which can separate the string into and array folder names on the backslash character.

If you wanted to limit to C:\ then you would just test the first memebr of the array for matching "C:". Otherwise test the subsequent levels against a list of acceptable paths.
 

Users who are viewing this thread

Back
Top Bottom