Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...