Solved

Inserting "folder" location in Hyperlink field

Posted on 2014-02-21
5
435 Views
Last Modified: 2014-02-22
Hi,

I have a hyperlink field in my form.

I want my users to
identify an excel spreadsheet in a specific folder and then

"paste" a link to that spreadsheet into my access form.


I want this to be a simply cut and paste.

Question: How can I CUT a hyperlink that hold my folder path AND my file name.


The end result should be something like;
C:\mydocuments\myExcel\Personal\Bankrec.xls

Note that I am already able to "cut" the folder path ...... but I am finding that I need to KEY in the actual file name.  I.e. I need to key in the "bankrec.xls" .... How do I avoid keying in the filename
0
Comment
Question by:Patrick O'Dea
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Sheils earned 500 total points
Comment Utility
You can do that with vba. The code is as follows:-

Function SelectFile() As String
      
        On Error GoTo ExitSelectFile
          
        Dim objFileDialog    As Object
        Set objFileDialog = Application.FileDialog(1)
          
        With objFileDialog
          
            .AllowMultiSelect = False
            .Show
               
            Dim varSelectedItem As Variant
      
            For Each varSelectedItem In .SelectedItems
      
                SelectFile = varSelectedItem
               
            Next varSelectedItem
                  
       End With
         
    ExitSelectFile:
      
    Set objFileDialog = Nothing
      
End Function

Open in new window


This will open the dialog box and you can select a file from any folder.

I have attached an example. Open the form and click the button to see how it works
dbselectfile.accdb
0
 

Author Closing Comment

by:Patrick O'Dea
Comment Utility
Purrfect!
0
 

Author Comment

by:Patrick O'Dea
Comment Utility
Actually,

Can I re-open this question??

This link insert fine into the table BUT .... it does not open when I click it in the form..??

Perhaps, the link should be enclosed in quote?? How do I do this?

Thanks
0
 
LVL 16

Expert Comment

by:Sheils
Comment Utility
Create a new module and paste in the following code:

Private Declare Function ShellExecuteA Lib "shell32.dll" _
(ByVal hWnd As Long, _
ByVal strOperation As String, _
ByVal strFile As String, _
ByVal strParameters As String, _
ByVal strDirectory As String, _
ByVal nShowCmd As Long) As Long
 
Private Declare Function GetDesktopWindow Lib "user32" () As Long
____________________________________________________________
 
Function OpenFile(strFilePath)
  
    lngreturn = ShellExecuteA(GetDesktopWindow(), "OPEN", strFilePath, "", "", vbNormalFocus)
  
    If Not ((lngreturn < 0) Or (lngreturn > 32)) Then
       
        MsgBox "Sorry, There was a problem opening the selected file", vbExclamation
  
    End If
  
End Function

Open in new window


Then in the form textbox on double click even add the following:

OpenFile(Me.textboxname)
0
 

Author Comment

by:Patrick O'Dea
Comment Utility
Thanks very much!

I got it now.  Very clever!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now