Drag file into Access, how to check the file details?

拜拜、爱过 提交于 2019-12-10 11:09:24

问题


I like to drag a file from Windows Explorer or an attachment from an Outlook mail into MS-Access.

I discovered already I can use the Access BoundObjectFrame (https://msdn.microsoft.com/en-us/library/office/ff835725.aspx) as a target to drag and drop files from the Windows Explorer.

And with the following code I see that something was dropped into the field:

Private Sub OLE1_GotFocus()
    Debug.Print "OLE1_GotFocus()"
    Debug.Print " OLE1.Value: " & OLE1.Value
End Sub

But the value is just some binary information. I want to know the file name which was dropped or I want to read what is in the dropped file (i.e. a text file is dropped).

I looked at all the properties and searched on the internet but I did not find a solution. I would have guessed many people tried before what I want to do.

Any ideas?


回答1:


I don't think the BoundObjectFrame will get you what you want.

I suggest using a ListView Control instead, an ActiveX control. It has inbuilt Drag&Drop support.

Demo:

On a form, insert a Microsoft ListView Control, version 6.0 ActiveX control.
Name it lvwDD.
In right-click, ListViewCtrl-object, Properties: set OLEDropMode to 1 - ccOLEDropManual.

Insert this event procedure:

Private Sub lvwDD_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)

    Dim i As Long

    ' https://msdn.microsoft.com/en-us/library/aa244109(v=vs.60).aspx
    Const vbCFFiles = 15

    If Data.GetFormat(vbCFFiles) Then

        ' https://msdn.microsoft.com/en-us/library/aa267471(v=vs.60).aspx
        For i = 1 To Data.Files.Count
            Debug.Print Data.Files(i)
        Next i

    Else
        Debug.Print "No file(s) dropped."
    End If

End Sub

Drag&Drop one or multiple files on the control, and see the output in the Immediate window (Ctrl+G).



来源:https://stackoverflow.com/questions/40083256/drag-file-into-access-how-to-check-the-file-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!