Solved

Inserting "folder" location in Hyperlink field

Posted on 2014-02-21
5
443 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

832 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