Hyperlink to Folder

123dstreet

Registered User.
Local time
Yesterday, 20:20
Joined
Apr 14, 2010
Messages
122
Hi All, I've been searching the forums for an answer to my question, but I probably didn't look hard enough. I have a form with a bunch of fields on it. One of the fields is a serial number field, which the user will enter manually for each new record. In the properties window I have changed the format so it is a hyperlink. Now all i want this hyperlink to do is find the folder that has the same name as the serial number.

Serial Number = 1234
\\N\manuf\BT100 Database\Production Runs\1234

What kind of code might I use for this??

Thanks in advance!!
 
1. To try out the following Code; Open a new Form in Design View.
2. Create a Command Button on the Form.
3. Display its Property Sheet and change the Name Property Value to Command0
4. Create a Text Box On the Form and change the Name Property Value to FileName.
5. Create another Text Box and name it as DefaultPath.
6. Display the VBA Module of the Form (View - ->Code).
7. Copy and Paste the following Code into the VBA Module.
Code:
Sub getFileName()
    ' Displays the Office File Open dialog to choose a file name
    ' If the user selects a file
    ' display it in the FileName control.
    Dim FileName As String
    Dim result As Integer
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select Employee Picture"
        .Filters.Add "All Files", "*.*"
        .Filters.Add "JPEGs", "*.jpg"
        .Filters.Add "Bitmaps", "*.bmp"
        .FilterIndex = 3
        .AllowMultiSelect = False
        .InitialFileName = "[B]\\N\manuf\BT100 Database\Production Runs\[/B]" & Me![DefaultPath]
        result = .Show
        If (result <> 0) Then
            FileName = Trim(.SelectedItems.Item(1))
            Me![FileName].Text = FileName
            Me![FileName].SetFocus

        End If
    End With
End Sub

Private Sub Command0_Click()
getFileName
End Sub
8. Save and Close the Form.
9. Open the Form in Design View.
10. Enter the Serial Number 1234 of the Folder (or whatever number of the existing folder under the highlighted default path in the code above) in the DefaultPath Text Box and click on the Command Button.
11. The Folder will open up.
12. You may select a file from the displayed window and click open to insert the selected file into the other Text Box.

You may modify the code and implement it in your Form.
 
Thanks for your response Apr Pillai. I'm just a little confused about some of this code, why do I need two text boxes? and what does the ".title=Select employee picture" have to do with anything? And is it not just possible to leave the original text box as a hyperlinked field that will find the related folder?
 
If all you want to do is open the directory for the specific serial number value and the location of the folders is fixed then you should be able to use something like this untested air code...

Code:
Application.FollowHyperLink "\\N\manuf\BT100 Database\Production Runs\" & [Serial Number] & "\"
 
ghudson.. that seems to work exactly how i need it to except, even when I click on the text box to enter the number, it automatically takes me to that folder, is there anyway to make it so that the command doesn't execute unless there are numbers in the text box??
 
I would put the code in a command button that the user has to click when they are ready to open the folder. Also add some code to stop the event if the serial number field is null.
 

Users who are viewing this thread

Back
Top Bottom