473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Hyperlinking to a folder, not a file

55
Does anyone know if it's possible to create a command button that opens a folder (in Windows Explorer or My Computer) rather than a specific file document? If so, how? I have a team of users that just wants a hyperlink from an Access record to a folder on the server containing a group of files related to the record, rather than creating an individual link to each file.

I'm working in Access 2000.

Angi
Apr 3 '08 #1
12 1898
nico5038
3,080 Expert 2GB
Not sure or a hyperlink will accept a folder, but personally I store the Path in a field in a record and use a button that activates a folder popup menu from windows to allow the user to select the folder from a treeview like (s)he's used from the explorer.

Expand|Select|Wrap|Line Numbers
  1. ' Form code for the OnClick event of a button named "GetFolder"
  2.  
  3. Private Sub btnGetFolder_Click()
  4. Dim strPath As String
  5.  
  6. strPath = fncGetFolder(vbCrLf & "Export to folder:", Me.Hwnd)
  7.  
  8. If Len(strPath) > 0 Then
  9.    Me.ExportFolder = strPath
  10.    ' force a save to get the path certainly available...
  11.    DoCmd.RunCommand acCmdSaveRecord
  12. End If
  13.  
  14. End Sub
  15.  
  16. ' Module code to handle the fncGetFolder() function by using ole32.dll 
  17.  
  18. Option Compare Database
  19. Option Explicit
  20.  
  21. Type shellBrowseInfo
  22.     hWndOwner      As Long
  23.     pIDLRoot       As Long
  24.     pszDisplayName As Long
  25.     lpszTitle      As String
  26.     ulFlags        As Long
  27.     lpfnCallback   As Long
  28.     lParam         As Long
  29.     iImage         As Long
  30. End Type
  31.  
  32. Const BIF_RETURNONLYFSDIRS = 1
  33. Const MAX_PATH = 260
  34.  
  35. Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
  36. Declare Function SHBrowseForFolder Lib "shell32" (lpbi As shellBrowseInfo) As Long
  37. Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _
  38.          ByVal lpBuffer As String) As Long
  39.  
  40. 'Then use the following function, supplying it the title you want to use for the dialog, and the handle of the calling form. (use the Me.hwnd property of the form):
  41. Public Function fncGetFolder(dlgTitle As String, Frmhwnd As Long) As String
  42.  
  43.     Dim intNullChr As Integer
  44.     Dim lngIDList As Long
  45.     Dim lngResult As Long
  46.     Dim strFolder As String
  47.     Dim BI As shellBrowseInfo
  48.  
  49.     With BI
  50.         .hWndOwner = Frmhwnd
  51.         .lpszTitle = dlgTitle
  52.         .ulFlags = BIF_RETURNONLYFSDIRS
  53.     End With
  54.  
  55.     lngIDList = SHBrowseForFolder(BI)
  56.     If lngIDList Then
  57.         strFolder = String$(MAX_PATH, 0)
  58.         lngResult = SHGetPathFromIDList(lngIDList, strFolder)
  59.         Call CoTaskMemFree(lngIDList)        'this frees the ole pointer to lngIDlist
  60.         intNullChr = InStr(strFolder, vbNullChar)
  61.         If intNullChr Then
  62.             strFolder = Left$(strFolder, intNullChr - 1)
  63.         End If
  64.     End If
  65.  
  66.     fncGetFolder = strFolder
  67.  
  68. End Function
  69.  
Hope this is also usefull.

Nic;o)
Apr 3 '08 #2
angi35
55
Not sure or a hyperlink will accept a folder, but personally I store the Path in a field in a record and use a button that activates a folder popup menu from windows to allow the user to select the folder from a treeview like (s)he's used from the explorer.
Well, the code is way beyond me, but I put it all in, and it worked. Amazing.

At least it partly worked. As I understand it, I should be able to go into the record, click the btnGetFolder and browse for a folder, then click "OK", and that path should be stored in a field in my table called ExportFolder that's also a control on my form. Then, I'm assuming, next time I click the button in this record, it should open the browser directly to that folder (?). Right now I open the browse box, follow the path to my selected folder, click "OK", and the browse box just goes away. Then when I click the button again, the box comes up and I start back at the beginning. How do I get it to store my selected path?

Also, when this is fully working, will it just save the path so that a user can see where the folder is but then has to go outside Access to Explorer to get to the folder and the files they're looking for -- or will it be possible for the user to open the folder and open documents within the folder from right there?

Thanks,
Angi
Apr 4 '08 #3
nico5038
3,080 Expert 2GB
I just use this to allow the user to navigate to a folder.
In my application I then execute some code to fill a table with the files of the folder and show that in a subform.
That (temp) table could be used with a YesNo field to allow for file(s) selection.

The code for the get files function is:
Expand|Select|Wrap|Line Numbers
  1. Function fncImportFilenames(strPath As String)
  2.  
  3. Dim rs As DAO.Recordset
  4. 'This function will import filesnames from the passed path into table "tblFiles"
  5. 'Make sure the strPath has a trailing "\"
  6. If Right(strPath, 1) <> "\" Then
  7.    strPath = strPath & "\"
  8. End If
  9.     Set rs = CurrentDb.OpenRecordset("tblFiles")
  10.     Dim fs, f, f1, fc, s, tso
  11.     Set fs = CreateObject("Scripting.FileSystemObject")
  12.     ' file directory
  13.     Set f = fs.GetFolder(strPath)
  14.     ' file collection
  15.     Set fc = f.Files
  16.     For Each f1 In fc
  17.         rs.AddNew
  18.         rs!FileName = f1.Name
  19.         rs!YesNo = False
  20.         rs.Update
  21.     Next
  22.  
  23. End Function
  24.  
Define a table named "tblFiles" with a 250 character FileName text field and a YesNo field named "YesNo".
Getting the idea ?

Nic;o)
Apr 4 '08 #4
ADezii
8,834 Expert 8TB
Does anyone know if it's possible to create a command button that opens a folder (in Windows Explorer or My Computer) rather than a specific file document? If so, how? I have a team of users that just wants a hyperlink from an Access record to a folder on the server containing a group of files related to the record, rather than creating an individual link to each file.

I'm working in Access 2000.

Angi
You can accomplish what you are requesting with as little as 4 lines of code, if you only intention is to View the Files within a specific Folder and not interact with them. For something this simple, I would use the Office File Dialog to allow the User to select only a single Folder, pass the Folder Name to the code below as strFolderName, then open it. If you are interested in this approach, let me know and I'll provide the remainder of the code.
Expand|Select|Wrap|Line Numbers
  1. Dim retVal As Variant
  2. Dim strFolderName As String
  3.  
  4. strFolderName = "C:\Test"
  5. retVal = Shell("Explorer.exe " & strFolderName, vbMaximizedFocus)
Apr 5 '08 #5
ADezii
8,834 Expert 8TB
Hello NIco, nice touch on your Folder Browsing code, very practical and familiar to the User.
Apr 5 '08 #6
nico5038
3,080 Expert 2GB
Hello NIco, nice touch on your Folder Browsing code, very practical and familiar to the User.
Thanks ADezii, came up with this when I ran into the .dll hell of the Open/Save dialog. This dialog worked on all PC's for me without "Reference errors" :-)

Nic;o)
Apr 6 '08 #7
ADezii
8,834 Expert 8TB
Thanks ADezii, came up with this when I ran into the .dll hell of the Open/Save dialog. This dialog worked on all PC's for me without "Reference errors" :-)

Nic;o)
Hello again , Nico. Are you aware of any other values for the ulFlags Element besides BIF_RETURNONLYFSDIRS within the ShellBrowseInfo Type? Just curiosity.
Expand|Select|Wrap|Line Numbers
  1. With BI
  2.   .hWndOwner = Frmhwnd
  3.   .lpszTitle = dlgTitle
  4.   'any other Flag values you are aware of?
  5.   .ulFlags = BIF_RETURNONLYFSDIRS
  6. End With
Apr 6 '08 #8
nico5038
3,080 Expert 2GB
Hello again , Nico. Are you aware of any other values for the ulFlags Element besides BIF_RETURNONLYFSDIRS within the ShellBrowseInfo Type? Just curiosity.
Expand|Select|Wrap|Line Numbers
  1. With BI
  2.   .hWndOwner = Frmhwnd
  3.   .lpszTitle = dlgTitle
  4.   'any other Flag values you are aware of?
  5.   .ulFlags = BIF_RETURNONLYFSDIRS
  6. End With
Found: http://www.earlsoft.co.uk/projects/c...lderDialog.cls
Holding:
Expand|Select|Wrap|Line Numbers
  1. 'Browse flags
  2. Private Const BIF_RETURNONLYFSDIRS = &H1 'For finding a folder to start document searching
  3. 'Private Const BIF_DONTGOBELOWDOMAIN = &H2 'For starting the Find Computer
  4. 'Private Const BIF_STATUSTEXT = &H4
  5. 'Private Const BIF_RETURNFSANCESTORS = &H8
  6. Private Const BIF_EDITBOX = &H10
  7. 'Private Const BIF_VALIDATE = &H20 'insist on valid result (or CANCEL)
  8. Private Const BIF_NEWDIALOGSTYLE = &H40 'New style dialog box
  9. Private Const BIF_NONEWFOLDERBUTTON = &H200 'Hide the new folder dialog box
  10. 'Private Const BIF_BROWSEFORCOMPUTER = &H1000 'Browsing for Computers.
  11. 'Private Const BIF_BROWSEFORPRINTER = &H2000 'Browsing for Printers
  12. Private Const BIF_BROWSEINCLUDEFILES = &H4000 'Browsing for Everything
  13.  
But never used another value as the one specified.

Nic;o)
Apr 6 '08 #9
ADezii
8,834 Expert 8TB
Found: http://www.earlsoft.co.uk/projects/c...lderDialog.cls
Holding:
Expand|Select|Wrap|Line Numbers
  1. 'Browse flags
  2. Private Const BIF_RETURNONLYFSDIRS = &H1 'For finding a folder to start document searching
  3. 'Private Const BIF_DONTGOBELOWDOMAIN = &H2 'For starting the Find Computer
  4. 'Private Const BIF_STATUSTEXT = &H4
  5. 'Private Const BIF_RETURNFSANCESTORS = &H8
  6. Private Const BIF_EDITBOX = &H10
  7. 'Private Const BIF_VALIDATE = &H20 'insist on valid result (or CANCEL)
  8. Private Const BIF_NEWDIALOGSTYLE = &H40 'New style dialog box
  9. Private Const BIF_NONEWFOLDERBUTTON = &H200 'Hide the new folder dialog box
  10. 'Private Const BIF_BROWSEFORCOMPUTER = &H1000 'Browsing for Computers.
  11. 'Private Const BIF_BROWSEFORPRINTER = &H2000 'Browsing for Printers
  12. Private Const BIF_BROWSEINCLUDEFILES = &H4000 'Browsing for Everything
  13.  
But never used another value as the one specified.

Nic;o)
Thanks alot for the info, Nico.
Apr 6 '08 #10
angi35
55
You can accomplish what you are requesting with as little as 4 lines of code, if you only intention is to View the Files within a specific Folder and not interact with them. For something this simple, I would use the Office File Dialog to allow the User to select only a single Folder, pass the Folder Name to the code below as strFolderName, then open it. If you are interested in this approach, let me know and I'll provide the remainder of the code.
Expand|Select|Wrap|Line Numbers
  1. Dim retVal As Variant
  2. Dim strFolderName As String
  3.  
  4. strFolderName = "C:\Test"
  5. retVal = Shell("Explorer.exe " & strFolderName, vbMaximizedFocus)

Hi ADezii -- It depends on what you mean by 'interact with them'. If you mean sharing data between the database and the external file, no, there's no need for that.

The situation I have is that there's a section of my database that captures key engineering info on each job record. The engineering department has seen how in other areas of the database, other departments are able to click a button and open an external document that's been hyperlinked. They'd like this function too, but they have so many files - engineering drawings and so on - for each job, that what they'd really like is to be able to click a button that would lead them to the folder where all these files are kept, and show all the files. From there they would double-click on the file of their choice and be able to open and work in it.

So what I'm imagining is creating a button... or a textbox that I'll make look and act like a button... that saves a path to the folder containing the engineering files related to the specific job record. The engineer user can click that button, which opens Explorer to that path and shows the folder with all its files & subfolders, and then he/she can open whatever file.

I guess the idea is to open a specific location in Explorer in the same way you can open a specific document in Word or Acrobat.

If something like that is possible with the code you have in mind, then I'd certainly like to have the rest of it!

Thanks.
Angi
Apr 9 '08 #11
angi35
55
I just use this to allow the user to navigate to a folder.
In my application I then execute some code to fill a table with the files of the folder and show that in a subform.
That (temp) table could be used with a YesNo field to allow for file(s) selection.

The code for the get files function is:
Expand|Select|Wrap|Line Numbers
  1. Function fncImportFilenames(strPath As String)
  2.  
  3. Dim rs As DAO.Recordset
  4. 'This function will import filesnames from the passed path into table "tblFiles"
  5. 'Make sure the strPath has a trailing "\"
  6. If Right(strPath, 1) <> "\" Then
  7.    strPath = strPath & "\"
  8. End If
  9.     Set rs = CurrentDb.OpenRecordset("tblFiles")
  10.     Dim fs, f, f1, fc, s, tso
  11.     Set fs = CreateObject("Scripting.FileSystemObject")
  12.     ' file directory
  13.     Set f = fs.GetFolder(strPath)
  14.     ' file collection
  15.     Set fc = f.Files
  16.     For Each f1 In fc
  17.         rs.AddNew
  18.         rs!FileName = f1.Name
  19.         rs!YesNo = False
  20.         rs.Update
  21.     Next
  22.  
  23. End Function
  24.  
Define a table named "tblFiles" with a 250 character FileName text field and a YesNo field named "YesNo".
Getting the idea ?

Nic;o)

Hi Nico,
I'm trying, but I'm afraid I'm not really getting the idea. First off, where do I put this function? I mean what event do I attach it to? How do I make it run?

Also, I don't think the "ExportFolder" field from the code you sent in your first post is doing anything. That's supposed to be the place that saves the path to the folder I select, right? -- so that the next time I click the btnGetFolder, it will show directly the folder I selected previously? Nothing is getting saved in that field. I can even delete the lines:

Expand|Select|Wrap|Line Numbers
  1. If Len(strPath) > 0 Then
  2.     Me.ExportFolder = strPath
  3.  
  4.     DoCmd.RunCommand acCmdSaveRecord
  5. End If
... it makes no difference to how the button operates.

I'm also wondering about the new function you gave me... Is it going to be possible to open each file from the subform? If a new file is added to the folder, or another file is deleted, is there going to be a way to update the subform that has all the file names? (I'm also assuming it's not going to matter if the files aren't the usual Office or pdf files - mostly they're in some sort of specialized engineering drawing software.)

In reality, I don't really need a subform with the specific files, unless that's the only way this can work (I already have so many subforms and nested subforms!). I don't need the files to be linked to the database. If it would be possible simply (simply?) to view the folder and all the files in it, then double-click on a file to open it without saving the file path in the database, that would be ideal. I explained the situation in more detail in the post I just put up in response to ADezii's suggestion.

Thanks for your help.
Angi
Apr 9 '08 #12
nico5038
3,080 Expert 2GB
For activating explorer with the registered path you can use te Shell() function like:

Expand|Select|Wrap|Line Numbers
  1. Shell ("explorer.exe " & Chr(34) & Me.txtPath & Chr(34))
  2.  
Nic;o)
Apr 9 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dan | last post by:
I am working on a C# ASP.NET project where I need to allow the user to browse to a folder. The only way I see how to do this is use <input type=file>. But this makes the user select a file and...
6
by: Nedu N | last post by:
Hi, I am trying to design a Home page for my applicatiion in which i want show the links for for some itms... I tried to put the following <td> <font face="Arial, Helvetica, sans-serif" ...
8
by: vinesh | last post by:
I have sample Asp.Net Web Application project. Let me know how to keep the files related to this project (like the webform.aspx, WebForm1.aspx.vb, WebForm1.aspx.resx) in a separate folder within a...
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
2
by: anguraj | last post by:
Hi My requirement is this...... I need to have a hypherlink option from the test box to be more clear. i need the have hypherlink option which we normally have in word/excel document........
1
by: NB | last post by:
I know this is not supposed to come here, but I need a help. How do I put different hyperlinks on one jpg file? Just like a map, each state would have a different link.... thaanks NB
2
by: reb0101 | last post by:
hey all, I would very much appreciate any help or ideas on how to do this as I am stumped. I need to develop an access database to track documents but also link to them. I’ll explain what it...
1
by: noservice | last post by:
I have recently uploaded my access 2003 tables to an SQL server. I've modified most of the code and everything is working properly except for the hyperlink fields. I have several fields which are...
9
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.