0

I am trying to open the window pictured in the following link using a commmand button in a form. Is it possible that anyone can show me how to do that?

http://www.utteraccess.com/forum/Launching-Attachments-Dia-t1652872.html

Thank you in advance!

Zack
  • 67
  • 3
  • 8
  • If you can program, you really shouldn't be using the attachment data type, because it's a multi-value field, and hides a lot from the programmer in service of ease of use for end users. You should use a proper N:N join table and store your attachment information there. And you should consider NOT storing the files in the database, but instead just the path/filename. The only thing that would change this advice would be if you're integrating with Sharepoint, in which case, you have to use the Attachment data type for compatibility. – David-W-Fenton May 13 '11 at 21:14
  • I'll second what Mr. Fenton is saying. Consider storing links in a text field (they can be relative if you prefer) that merely help you find the file. What sort of attachments do you plan to store? Are you hoping to allow view/previewing of these attachments within your application? – HK1 May 15 '11 at 16:32
  • @David-W-Fenton I understand that and the logic. However, the only issue is that the database is on a network location. So if one user links a document that is saved locally then other users will not be a able to access it. – Zack May 16 '11 at 12:45
  • also, though you may not believe it to be good practice, are either of you aware on how to open this dialog window? – Zack May 16 '11 at 12:46
  • Re: Network Location - All network locations should be accessed using a drive letter. If the user links a document that's stored locally this is a problem to be taken up on a different level. I've learned not to waste lots of time programming around this type of stupidity. If users make this mistake someone needs to educate them on the right way to do it. – HK1 May 18 '11 at 20:33
  • Disagree on drive letter -- UNC is going to work on all computers, regardless of local drive mapping. But that doesn't really address the question of a user pointing to a file stored locally. – David-W-Fenton May 18 '11 at 21:31
  • Don't allow the user to create a link to any file that is not in a designated location (e.g., on a server accessible to all users). This means you will have to allow the user to point to a local file and move it to the server. Whether you more or copy is up to you. – David-W-Fenton May 18 '11 at 21:32

2 Answers2

1

I am not sure if you can call this specific dialog, but what you can do is use the generic FileDialog with the FilePicker option. Then save use that path to the file and copy the specific file to a shared location (probably somewhere where your backend is stored too). Then in your table, you save the path to that new location.

The use of the filedialog is explained in the help:

Sub Main()

    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is aString,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is aString that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem

            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing

End Sub 

And through Google, I came across this (old) topic giving even more reasons not to use the attachement type in your table (update, insert,... queries won't work that easily i.e.).

Since I follow David.W.Fenton's comment on my answer, I would also recommend reading the following topic on SO. Especially the answer by Mitch Weath gives some extra information about using the Win32 API for the Open file dialog.

Community
  • 1
  • 1
Yoh
  • 678
  • 1
  • 10
  • 18
  • I would recommend against using the Office FileDialog wrapper and instead use a Windows API call. The latter will work as long as the Win32 API is supported, while MS might decide to remove the FileDialog wrapper (as they removed the FileSearch object in Office 2007). – David-W-Fenton May 18 '11 at 21:33
  • I understand. Updated my answer with some info about this. – Yoh May 19 '11 at 12:08
  • I wanted to thank both of you very much -- Yohsoog and David. You both went very far to help me out and provide me with a very helpful and complete answer! – Zack May 20 '11 at 14:37
0

The answer I found to this is so simple that I must assume it wasn't available when the question was first posted. But as of at least 2017, you can use:

Private Sub MyAttachment_GotFocus()
    RunCommand acCmdManageAttachments
End Sub
Shawn V. Wilson
  • 1,002
  • 3
  • 17
  • 42