none
microsoft access - set default path for attachments RRS feed

Answers

  • Can I specify the file path when a user double-clicks an attachment?

    Thanks, Jim

    Hi Jim. For your install of Access, you can go to File > Options > General > Default database folder and set it to whichever folder you want to be the default. Hope that helps...
    Monday, May 16, 2016 1:52 AM
  • You can use this code to start in any directory without the need to redefine anything from standard values. Put it in the Form:

    Option Compare Database
    Option Explicit
    
    Const msoFileDialogSaveAs = 2
    
    Const DEFAULTDIR = "E:\Temp\"   '<- Set your initial directory here
    
    
    Sub Attach_DblClick(Cancel As Integer)
        Dim Filename As String
        Dim fl As Field2
    
        Filename = Me.SaveAsDialog(DEFAULTDIR)
        If Filename <> "" Then
            Set fl = Me.Recordset("Attachment")
            fl(0).SaveToFile Filename
        End If
    End Sub
    '******************************************
    '* Save As-dialog
    '*
    Function SaveAsDialog(Filepath As String) As String
        Dim fd As Object
        Dim FileSelected As String
    
        Set fd = Application.FileDialog(msoFileDialogSaveAs)
        With fd
            .Title = "Save the attachment"
            .AllowMultiSelect = False
            .InitialFilename = Filepath
            If .Show Then FileSelected = .SelectedItems(1)
        End With
        SaveAsDialog = FileSelected
    End Function
    


    Best regards, George

    Monday, May 16, 2016 5:38 AM

All replies

  • Hi Jim Thacker,

    do you want to set a default path for attachment to save in access. means when you upload it in a form then it should save on particular location

    or

    you want to display the path of an attachment that are already saved in a table.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 12, 2016 1:14 AM
    Moderator
  • Hi Jim Thacker,

    if you looking for save an attachment at particular location please see the example below.

    '  Instantiate the parent recordset.  
       Set rsEmployees = db.OpenRecordset("Employees") 
      
       … Code to move to desired employee 
      
       ' Instantiate the child recordset. 
       Set rsPictures = rsEmployees.Fields("Pictures").Value  
     
       '  Loop through the attachments. 
       While Not rsPictures.EOF 
      
          '  Save current attachment to disk in the "My Documents" folder. 
          rsPictures.Fields("FileData").SaveToFile _ 
                      "C:\Documents and Settings\Username\My Documents" 
          rsPictures.MoveNext 
       Wend 
    

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 12, 2016 1:23 AM
    Moderator
  • Deepak,

    When I double click on the Attachment field and click Add, it takes me to my Documents folder.  I then have to navigate to the folder I have my images in.  I want it to take me directly to my images folder instead.

    Thanks, Jim

    Saturday, May 14, 2016 8:42 PM
  • If you mean without VBA, no (unless you redefine the My Documents Folder).
    With VBA: Absolutely! Please submit the VBA code pertinent to the save operation.

    Best regards, George

    Sunday, May 15, 2016 9:24 AM
  • George,

    I don't have any VBA Code yet.

    I presume I would have to set up a Double-Click event on the Attachment field to override the default action.

    Thanks, Jim

    Sunday, May 15, 2016 7:28 PM
  • Can I specify the file path when a user double-clicks an attachment?

    Thanks, Jim

    Hi Jim. For your install of Access, you can go to File > Options > General > Default database folder and set it to whichever folder you want to be the default. Hope that helps...
    Monday, May 16, 2016 1:52 AM
  • Hi Jim Thacker,

    I think the suggestion given by the DB guy can solve your issue and you not need to code for that if the suggestion worked.

    please check it and let us know.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 16, 2016 5:28 AM
    Moderator
  • You can use this code to start in any directory without the need to redefine anything from standard values. Put it in the Form:

    Option Compare Database
    Option Explicit
    
    Const msoFileDialogSaveAs = 2
    
    Const DEFAULTDIR = "E:\Temp\"   '<- Set your initial directory here
    
    
    Sub Attach_DblClick(Cancel As Integer)
        Dim Filename As String
        Dim fl As Field2
    
        Filename = Me.SaveAsDialog(DEFAULTDIR)
        If Filename <> "" Then
            Set fl = Me.Recordset("Attachment")
            fl(0).SaveToFile Filename
        End If
    End Sub
    '******************************************
    '* Save As-dialog
    '*
    Function SaveAsDialog(Filepath As String) As String
        Dim fd As Object
        Dim FileSelected As String
    
        Set fd = Application.FileDialog(msoFileDialogSaveAs)
        With fd
            .Title = "Save the attachment"
            .AllowMultiSelect = False
            .InitialFilename = Filepath
            If .Show Then FileSelected = .SelectedItems(1)
        End With
        SaveAsDialog = FileSelected
    End Function
    


    Best regards, George

    Monday, May 16, 2016 5:38 AM