X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Drag And Drop Files (feedme), Any Version    
post Sep 15 2011, 12:19 PM

UtterAccess Administrator
Posts: 10,284
Joined: 7-December 09
From: St. Augustine, FL

There's two demos here. The FeedMe demo is additional functionality to the DragDrop stuff. The DragDrop has the real work in it. The GUI class is required for the FeedMe functoinality. The latest version at the time of this post is included in the FeedMe demo.
This demo shows how to implement dragging and dropping of files from windows explorer into your application.
Included in the zip file is a complete documentation of the DragDrop functionality, starting with simple usage and covering most aspects that the average user might come across.
I've seen two demos of this before: one which utilizes a subform as the "drop area", and one that does not. Myself and at least one other (thanks Alan) experienced problems when attempting to use the drag/drop API functionality in a standalone form: the only way to successfully implement it with the few examples to be found is to setup the drop area as a subform.
The problem is with a callback function from the API that clogs up the VBA project. The callback function required for drog/dropping has to process every system message sent to the window we're using. In the other demos I looked at, hook into the callback is placed when the form is opened and removed when the form is closed. This means that throughout the life of the (standalone) form, that callback is running rather madly: so much that better than 90% of the time it was crashing Access.
When used in a subform, and the hook is placed at the open of the subform and removed at the close of the subform, the behavior is much better. For whatever reason, subform window callbacks do not seem to run unless the mouse is placed over the subform. The general result is a satisfactory implementation of drop/dropping: the subform callbacks are not enough to crash Access. Just don't open the subform as a standalone form, unless you want to crash Access.
When I initially set out to use drag/srop functionality, it was intended to drop a file into a textbox that would enter said file into the system. At the time, I wasn't aware of the subform implementation, and set out to find a way to keep Access from crashing. The solution I came to, the one posted here, works to drop files into a specified control on a standalone form.
The means I used to obtain this was to remove the hooking from the form's open/unload events, and instead have the hook only active while the cursor is over the control that takes the file. This works well as a standalone form implementation, but there is one minor quirk:
The form, either standalone or sub, needs to be registered to accept drag/dropped files. When this form is registered, dragging files anywhere over the form results in the cursor changing from the standard pointer to the dragging icon. This is misleading in the standalone/control implementation as it more or less tells the user that they can drop the files anywhere on the form, but in fact they can only drop them into the control. I cannot think of any workaround to this, but you may or may not view it as a dealbreaker.
In retrospect, using the subform implementation with a sub just large enough to enclose the required control may be a preferable method of handling it: then the user will only see the drag/drop icon in a valid drop area, though loading a subform, depending on how many, will add considerably to the form's load time.
One major advantage to using the MouseOver event to hook into the callback rather than a form's open/close (or load/unload) is that we can now implement drag/drop capabilities one more than one open form at a time. Because the callback needs to be in a standard module, it becomes quite difficult to maintain instancing directives on it. While the message callback does utilizes the form's Handle, I don't know that I'd trust it enough to have two subforms open at once and have the function continuously running and able to keep everything sorted. Using the MouseOver of a control (or the Detail section of a subform) ensures that the callback only has to handle one window at a time.
DragDrop FeedMe
The DragDrop FeedMe demo contains the same drag/drop code as the DragDropAPI demo, but this one has functionality that hides the Access window and pops up a small form so the user can drag files into it without having to work around the Access app or resize it to get files:
The V2 FeedMe includes a class module and demo for it to select a variety of different settings and options. The GUI and modDragDrop modules are required and included in the demo. I haven't done much for documentation on it yet, but there's not really a lot to document on it. The class provides properties and one method, set them as desired, and that's about it.
V2 Demo Snapshot:
Attached File  FeedMe_SS.gif ( 90.88K )Number of downloads: 1299


(please see this post for a minor bug fix where previous files aren't properly cleared - thanks Detire!)
Attached File  DragDrop_v1.0.1_Documentation__Revision_0_.pdf ( 70.01K )Number of downloads: 901
Attached File  DragDrop_v1.0.1.zip ( 132.21K )Number of downloads: 1016

Attached File  DragDrop_FeedMe_v2.0.zip ( 96.11K )Number of downloads: 874
Attached File  DragDrop_FeedME_v2.0_Acc2010_32___64bit.zip ( 209.52K )Number of downloads: 905

Older versions:
Attached File  DragDropAPI.zip ( 49.43K )Number of downloads: 426
Attached File  DragDrop_FeedMe.zip ( 33.74K )Number of downloads: 363

Revisions of DragDrop:
'V1.0.1 2011-09-29
'  Modifications from original:
'    - Added link resolution
'    - Added DragDropRemoveDuplicates()
'  Known Bugs
'    - Link resolution doesn't seem to work on
'      some .lnk files.
'      You can modify pfGetShortcutTargets to
'      turn off shortcut target resolution and
'      always return .lnk or .URL files.
Go to the top of the page
post May 13 2015, 02:05 PM

UtterAccess VIP
Posts: 4,053
Joined: 19-October 10

Hi all,

I've been talking to Jack about this as I found that it wouldn't allow attachments into a control when the form is a subform. With Jack's permission I have reworked some of the code so that it will be able to work out if a form has a parent (and in turn if that has a parent) and ensure the code still works.

I have added 5 new forms to demonstrate how this nesting works. Select any level and the drag and drop still runs now.
I have noted the code seems to stop working intermittently if you open and close forms in the same session and this is consistently problematic in my revised version and Jack's original version.
I will try to convert this into a class rather than a vanilla module to try to eliminate this problem and allow multiple drop controls on the same form. I will also see if I can do some work to sort out the issue Jack raised about the icon changing on whole form including parents.
Attached File(s)
Attached File  DragDrop_v1.0.2_Demo_A2K.zip ( 35.71K )Number of downloads: 499
Go to the top of the page
post Mar 3 2016, 05:53 PM

Posts: 1
Joined: 3-March 16


I have to change the function to allow it to work in any context in the subform:

Private Function ReturnSubformObject(hWnd As Long, frm As Access.Form) As Access.Form
'Added by Jon smith

On Error GoTo NoSubform

'Dim frm1 As Access.SubForm
'    For Each frm1 In frm
'        If frm1.Form.hWnd = hWnd Then
'            Set ReturnSubformObject = frm1.Form
'            Exit For
'        End If
'        Set ReturnSubformObject = ReturnSubformObject(hWnd, frm1.Form)
'        If Not ReturnSubformObject Is Nothing Then Exit For
'    Next
'Debug.Print "Try finding subform: " & frm.Name

'Change by Jonathan Bilodeau

    Dim ctl As Access.Control
    For Each ctl In frm.Controls
        Debug.Print frm.Name & " " & ctl.Name
        If ctl.Properties("ControlType") = acSubform Then
            If ctl.Form.hWnd = hWnd Then
                Set ReturnSubformObject = ctl.Form
                Exit For
            End If
        End If
    Next ctl
'This code errors if no subform can be found but thats ok as it'll return nothing
End Function

I do not understand why, but that have fix my issue in Access 2010 French feel free to update it as you need.

Go to the top of the page
post Jan 30 2017, 08:31 PM

Posts: 4
Joined: 11-August 16

First let me say I am extremely grateful that you posted this! I wanted to give you credit where it was due smile.gif. On another hand i took it one step further by adding a file import/logging based on the files that were dragged and dropped. I wanted allow a user to drag the files he wanted to add to the database, copy the file to the local server, and then hyperlink to it. This way it is not stored in the database and is extremely easy to use. I know I did not clean up the code for posting, but wanted to share it as everyone else has been more than generous sharing their coding. This script will add on the functionality below;

1. Take files listed in the ctrl box from feed me and log them on another table
2. Take the files and copy them to the folder/server specified

On Error GoTo salah
If txtAttachmentTypeSelection <> "" Then
'DoCmd.RunCommand acCmdSaveRecord '<---- save
'DoCmd.GoToRecord , , acNewRec '<---- new
Dim i As Integer
Dim a As Variant
Dim foldercopy As String
Dim ParentDir As String
Dim REGION As String
Dim Str As String
Dim SAP As String

a = Split(ctlDropBox.Value, vbCrLf)
'MsgBox UBound(a)
For i = 0 To UBound(a)
DoCmd.GoToRecord , , acNewRec '<---- new
txtOriginalFile.Value = a(i)

REGION = TempVars!Regiontxt
Str = TempVars!Strtxt
SAP = TempVars!SAPtxt

If TempVars!WorktypeID = 13 Then
ParentDir = "V:\Server\"

foldercopy = ParentDir & REGION
If Dir(foldercopy, vbDirectory) = "" Then MkDir foldercopy

foldercopy = foldercopy & "\" & SAP
If Dir(foldercopy, vbDirectory) = "" Then MkDir foldercopy

foldercopy = foldercopy & "\" & Str
If Dir(foldercopy, vbDirectory) = "" Then MkDir foldercopy

foldercopy = foldercopy & "\" & Me.txtAttachmentTypeSelection
If Dir(foldercopy, vbDirectory) = "" Then MkDir foldercopy

'foldercopy = "V:\Server\" & REGION & "\" & SAP & "\" & Str & "\" & Me.txtAttachmentTypeSelection
End If
txtDestinationFolder.Value = foldercopy & "\" & Dir(a(i)) ' & "#" & foldercopy & "\" & Dir(a(i))
txtfilename.Value = Left(Dir(a(i)), (InStr(1, Dir(a(i)), ".")) - 1)
txtDateAdded.Value = Date
txtCLPID.Value = TempVars!CLPID
txtAttachmentType.Value = Me.txtAttachmentTypeSelection.Value

'Call FileCopy(OriginalFile.Value, "E:\Test\" & Dir(a(i)))
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile(txtOriginalFile.Value, foldercopy & "\" & Dir(a(i)))

DoCmd.RunCommand acCmdSaveRecord '<---- save
Next i
MsgBox "Please specify what type of files you are importing in the Attachment Type Dropdown. Thank you!", vbOKOnly + vbExclamation, "Error"
End If

MsgBox "Files have been uploaded!"

Exit Sub
MsgBox Err.Number & " - " & Err.Description
End Sub
Go to the top of the page
post Aug 6 2018, 10:46 AM

Posts: 1
Joined: 6-August 18

Thank you! I have been able to get this to work perfectly on our Server and a Windows 8 machine, but drop and drag seems to fail on all Windows 10 machines. Any idea for a work-a-round?


Go to the top of the page
post Sep 22 2018, 07:01 PM

UtterAccess VIP
Posts: 19,009
Joined: 29-September 03
From: Oklahoma City, Oklahoma

I have many users still on Windows 7 and 8.1 and this code works fine for them with Access 32-bit 2007/2010/2013/2016 full and runtime.

I have experienced the same issue as johnny99 with the dropping (appears to drag just fine) not working in Windows 10 32-bit or 64-bit with Access 32-bit 20072010/2013/2016.

I can back here hoping for an update or workarounds to to fix the Windows 10 issue.

Time to ask the Search Engine Gods.

Boyd Trimmell aka Hi Tech Coach ( HiTechCoach.com free Access stuff)
Microsoft MVP 2010-2015 - Access Expert
Inventory Control, Accounting, BPM, and CRM Software Developer
"If technology doesn't work for people, then it doesn't work."
Go to the top of the page
post Oct 30 2018, 12:59 PM

Posts: 1
Joined: 30-October 18

Same issue here. I just downloaded and have not tried to fix as yet. Still wrapping my mind around the code.
Go to the top of the page
post Aug 15 2019, 03:14 PM

Posts: 2
Joined: 15-August 19

So as have been playing the with the code and using the debug panel i see that in windows 10 when you drop, the hook turns on. The issue i think is that it doesn't see the mouse event til after you have finished your drop and as such does not record the message any longer. Once i do the drag, the hook stays on and as such then the second go around it works. Then once it is done the hook turns off. So now i have to double it up again.

I have also noticed that as long as the focus is not on Access the hook stays open and does not close. So if i start the hook on open and have it open something else, then it stays open and accepts the file.

I think it has something to do with Windows 10 and how Access handles the drag and drop. Because even though i have this issue i can see in Access where it wants to do its highlight on the Navigation when i am bringing the file overtop. It just doesn't seem to keep firing the Hooks as you go overtop the form in order to open the hook and then detect the drop and close the hook.
Go to the top of the page
post Aug 15 2019, 04:23 PM

Posts: 2
Joined: 15-August 19

Also, forgot to mention how i got it to work.

I commented out some code below from Function DragDropCallback
'  intCallCount = intCallCount + 1
'  If intCallCount >= DDH_MAXCALLS Then
'    intCallCount = 0
'    DragDropSetHook False, hwnd
'  End If

Then i did the

Form_Open as DragDropSetHook True, Me.hwnd
Form_Close as DragDropSetHook False, Me.hwnd

Then made my form that they were dragging to Modal and Popup so that no other form can be used. Made a label caption at the bottom of the form to show the filename that was moved so that they knew it worked.
This post has been edited by ruaduck: Aug 15 2019, 04:27 PM
Go to the top of the page
post Aug 18 2019, 10:38 PM

Posts: 282
Joined: 19-April 04
From: Toronto


That's very exciting that you got it working! I think I must be not following the instructions quite right.

- I commented out the code that you specified
- I was unclear as to this part:

Form_Open as DragDropSetHook True, Me.hwnd
Form_Close as DragDropSetHook False, Me.hwnd

What I think you meant was that in the On Open event of the form that you drop onto (frmFeedMe in the example), you put the line: DragDropSetHook True, Me.hwnd and on the close event of this form you put DragDropSetHook False, Me.hwnd.

I did that and it does drop onto the form, which I have never been able to happen since I got Win 10! However, the application freezes up and I have to CTRL + ALT + DEL out of it. I must be missing a detail. However it does look promising!

Thank you

Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    14th December 2019 - 10:06 PM