Solved

Inserting "folder" location in Hyperlink field

Posted on 2014-02-21
5
444 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
ID: 39878895
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
ID: 39879158
Purrfect!
0
 

Author Comment

by:Patrick O'Dea
ID: 39879174
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
ID: 39879801
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
ID: 39879842
Thanks very much!

I got it now.  Very clever!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

790 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