attachments stored elsewhere

splreece

Registered User.
Local time
Today, 16:11
Joined
Jun 2, 2016
Messages
40
hi all,

just a quick one. Is it possible to use the attachments element on a userform, but rather than it save itself in the database, it simply links to a directory (or copies the resource into specified directory).

I potentially have 2000+ new entries per year so if all have attachments the dbase file will be sizeable.
 
I would store the path to the document, instead of the item as an attachment.
This will save a lot of space in the db.
 
thanks Ranman

Is there a way to do this programmatically.

My users are not very smart when it comes to naming/IT etc.

So ideally, I would have a button that they click to select their file, and as part of the vba process, their file would copy to a predefined directory and then take the new location and filename and place into a link field (hyperlinked of course).

Is there a way to automate this?
 
an ATTACH FILE button will ask user to select a file. then either use THAT path or write it to another pre-destined path.

Code:
sub btnAttachFile_click()
   vFile = UserPick1File ("c:\defaultFolder\")
   if vFile <> "" then         txtFile = vFile     'save the picked file
end sub
another VIEW button to view the saved file in the textbox.

usage:
Code:
sub btnView_click()
  OpenNativeApp ME.txtBox
end sub
Paste the following code into a module.
OpenNativeApp() will open ANY file in its native application.
will open the doc in Word if the item in txtBox is C:\myfile.doc
will open it in acrobat if its a pdf file.
etc


Code:
'Attribute VB_Name = "modNativeApp"
'Option Compare Database
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, 

ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, 

ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&


Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String

r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub


Public Function UserPick1File(Optional pvPath)
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr  As String, sExt As String


'===================
'YOU MUST ADD REFERENCE : Microsoft Office 11.0 Object Library, in vbe menu, TOOLS, REFERENCES
'===================

With Application.FileDialog(msoFileDialogFilePicker)   
    .AllowMultiSelect = False
    .Title = "Locate a file to Import"
    .ButtonName = "Import"
    .Filters.Clear
     '.Filters.Add "CSV Files", "*.csv"
     '.Filters.Add "Excel Files", "*.xls;*.xlsx"
    .Filters.Add "All Files", "*.*"
    .InitialFileName = pvPath
    .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
    
        If .Show = 0 Then
           'There is a problem
           Exit Function
        End If
    
    'Save the first file selected
    UserPick1File = Trim(.SelectedItems(1))
End With
End Function
 

Users who are viewing this thread

Back
Top Bottom