Database with table for Documents on Server (1 Viewer)

MayoRR5

Registered User.
Local time
Today, 06:43
Joined
Aug 27, 2009
Messages
31
Hi guys,

I have a database in use at the moment for Document Control but I want to add the ability to click a link for a document and open it from a specific location (one folder with all files) on our server.

I was just hoping for some general advice, do's and don'ts, before I get started.

All files are scanned and saved as PDF's and I want to reference a "true" server location (\\SERVER\FOLDER1\FOLDER2).

Thanks in advance for the help :D
 

paulscherm

Registered User.
Local time
Yesterday, 22:43
Joined
Aug 27, 2012
Messages
16
Set the control as a hyperlink. Use the table design.:eek:
 

MayoRR5

Registered User.
Local time
Today, 06:43
Joined
Aug 27, 2009
Messages
31
Paul, I will have about 100,00 documents to start with and then continuing on from there. Unless you want to hyperlink them for me, then be my guest :p haha
 

spikepl

Eledittingent Beliped
Local time
Today, 07:43
Joined
Nov 3, 2010
Messages
6,142
If all files are in the same folder then save just the file name in your table. You can then construct the URL on the fly, and use the FollowHyperlink method, e.g., in the double-click event of the control showing the file name.
 

Thales750

Formerly Jsanders
Local time
Today, 01:43
Joined
Dec 20, 2007
Messages
2,150
Allen Browne wrote this.




This could be a command button

The following example is used to list all of the files in a "User" Download folder

Local Call:

Code:
 Dim FilePath As String
  
 FilePath = Environ("USERPROFILE") + "\Downloads"
  
 Call ListFilesToTable(FilePath)
If you wanted to hard code the folder path it could look something like this

Code:
Call ListFilesToTable("C:\Data\HCDC\HarisCountyDownloads")
Module:

Code:
 Option Compare Database
Option Explicit
 'list files to tables
'http://allenbrowne.com/ser-59alt.html
 Dim gCount As Long ' added by Crystal
 Sub runListFiles()
    'Usage example.
    Dim strPath As String _
    , strFileSpec As String _
    , booIncludeSubfolders As Boolean
    
    strPath = "E:\"
    strFileSpec = "*.*"
    booIncludeSubfolders = True
    
    ListFilesToTable strPath, strFileSpec, booIncludeSubfolders
End Sub
 'crystal modified parameter specification for strFileSpec by adding default value
Public Function ListFilesToTable(strPath As String _
    , Optional strFileSpec As String = "*.*" _
    , Optional bIncludeSubfolders As Boolean _
    )
On Error GoTo Err_Handler
    'Purpose:   List the files in the path.
    'Arguments: strPath = the path to search.
    '           strFileSpec = "*.*" unless you specify differently.
    '           bIncludeSubfolders: If True, returns results from subdirectories of strPath as well.
    'Method:    FilDir() adds items to a collection, calling itself recursively for subfolders.
   ' DoCmd.SetWarnings False
    Dim colDirList As New Collection
    Dim varitem As Variant
    Dim rst As DAO.Recordset
    
   Dim mStartTime As Date _
      , mSeconds As Long _
      , mMin As Long _
      , mMsg As String
      
   mStartTime = Now()
   '--------
    
    Call FillDirToTable(colDirList, strPath, strFileSpec, bIncludeSubfolders)
      
   mSeconds = DateDiff("s", mStartTime, Now())
   
   mMin = mSeconds \ 60
   If mMin > 0 Then
      mMsg = mMin & " min "
      mSeconds = mSeconds - (mMin * 60)
   Else
      mMsg = ""
   End If
   
   mMsg = mMsg & mSeconds & " seconds"
   
  ' MsgBox "Done adding " & Format(gCount, "#,##0") & " files from " & strPath _
     ' & IIf(Len(Trim(strFileSpec)) > 0, " for file specification --> " & strFileSpec, "") _
     ' & vbCrLf & vbCrLf & mMsg, , "Done"
  
Exit_Handler:
   SysCmd acSysCmdClearStatus
   '--------
    
    Exit Function
 Err_Handler:
    MsgBox "Error " & Err.Number & ": " & Err.Description, , "ERROR"
    
    'remove next line after debugged -- added by Crystal
    Stop: Resume 'added by Crystal
    
    Resume Exit_Handler
End Function
 Private Function FillDirToTable(colDirList As Collection _
    , ByVal strFolder As String _
    , strFileSpec As String _
    , bIncludeSubfolders As Boolean)
   
    'Build up a list of files, and then add add to this list, any additional folders
    On Error GoTo Err_Handler
    
    Dim strTemp As String
    Dim colFolders As New Collection
    Dim vFolderName As Variant
    Dim strSQL As String
     'Add the files to the folder.
    strFolder = TrailingSlash(strFolder)
    strTemp = Dir(strFolder & strFileSpec)
    Do While strTemp <> vbNullString
         gCount = gCount + 1
         SysCmd acSysCmdSetStatus, gCount
         strSQL = "INSERT INTO Files " _
          & " (FName, FPath) " _
          & " SELECT """ & strTemp & """" _
          & ", """ & strFolder & """;"
         CurrentDb.Execute strSQL
        colDirList.Add strFolder & strTemp
        strTemp = Dir
    Loop
     If bIncludeSubfolders Then
        'Build collection of additional subfolders.
        strTemp = Dir(strFolder, vbDirectory)
        Do While strTemp <> vbNullString
            If (strTemp <> ".") And (strTemp <> "..") Then
                If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
                    colFolders.Add strTemp
                End If
            End If
            strTemp = Dir
        Loop
        'Call function recursively for each subfolder.
        For Each vFolderName In colFolders
            Call FillDirToTable(colDirList, strFolder & TrailingSlash(vFolderName), strFileSpec, True)
        Next vFolderName
    End If
 Exit_Handler:
    
    Exit Function
 Err_Handler:
    strSQL = "INSERT INTO Files " _
    & " (FName, FPath) " _
    & " SELECT ""  ~~~ ERROR ~~~""" _
    & ", """ & strFolder & """;"
    CurrentDb.Execute strSQL
    
    Resume Exit_Handler
End Function
 Public Function TrailingSlash(varIn As Variant) As String
    If Len(varIn) > 0& Then
        If Right(varIn, 1&) = "\" Then
            TrailingSlash = varIn
        Else
            TrailingSlash = varIn & "\"
        End If
    End If
End Function
 

MayoRR5

Registered User.
Local time
Today, 06:43
Joined
Aug 27, 2009
Messages
31
Update guys. I was able to hyperlink them easily enough after a little tinkering. In hindsight it was pretty obvious.

All I had to do was create a hyperlink with the folder address and then add the document names (which are based on fields in the table) and add as a new field to my table.

Now all I do is set a button to open the document, based on the hyperlink contents, in a form and voila.

Thanks for the input guys!! Muchos appreciated.

Shaun
 

Users who are viewing this thread

Top Bottom