Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...