UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Drag And Drop Files (feedme), Any Version    
 
   
jleach
post Sep 15 2011, 12:19 PM
Post#1


UtterAccess Administrator
Posts: 10,473
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.
DragDropApi
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: 1355

Cheers

(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: 925
Attached File  DragDrop_v1.0.1.zip ( 132.21K )Number of downloads: 1050

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

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

Revisions of DragDrop:
CODE
'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
 
JonSmith
post May 13 2015, 02:05 PM
Post#2


UtterAccess VIP
Posts: 4,073
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: 529
 
Go to the top of the page
 
Jonathan
post Mar 3 2016, 05:53 PM
Post#3



Posts: 1
Joined: 3-March 16



Hi,

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


CODE
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
    
NoSubform:
'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.

Regards,
Go to the top of the page
 
leviathanxx
post Jan 30 2017, 08:31 PM
Post#4



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
Else
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
salah:
MsgBox Err.Number & " - " & Err.Description
End Sub
Go to the top of the page
 
johnny99
post Aug 6 2018, 10:46 AM
Post#5



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?

Thanks

J99
Go to the top of the page
 
HiTechCoach
post Sep 22 2018, 07:01 PM
Post#6


UtterAccess VIP
Posts: 19,037
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
 
courna
post Oct 30 2018, 12:59 PM
Post#7



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
 
ruaduck
post Aug 15 2019, 03:14 PM
Post#8



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
 
ruaduck
post Aug 15 2019, 04:23 PM
Post#9



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
CODE
'  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
 
shadow
post Aug 18 2019, 10:38 PM
Post#10



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


Ruaduck:

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:

QUOTE
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
 
EddieN1
post Jan 4 2020, 10:01 PM
Post#11



Posts: 1
Joined: 4-January 20



I was wondering if anything had ever been resolved for dragging and dropping a filename onto an Access Text Box when running Windows 10?

Thanks, Eddie
Go to the top of the page
 
JonSmith
post Jan 15 2020, 09:08 AM
Post#12


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



I thought I'd posted on some threads regarding this years ago to provide a fix.

I have a totally alternative approach to provide the same functionality.
I am pretty sure I've refined this code since this example but I havent got the time now to properly check. Consider this attached a functional demo version, if I get chance I'll follow up later with a copy worthy of the code archive.

@admins, feel free to remove if you want to keep this thread clean and only focus on the original code, ask EddieN1 to open a new thread and pm or something and we can continue there smile.gif
Attached File(s)
Attached File  AttachmentExample.zip ( 88.44K )Number of downloads: 61
 
Go to the top of the page
 
shadow
post Jan 15 2020, 06:42 PM
Post#13



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


@JonSmith

This is the first I'm seeing this. I tested your example on Win 10 and it works perfectly!

My only problem now is that after opening it up and looking at the code, I actually have no idea how to utilize it in my own projects frown.gif

If you've posted documentation, can you please link to somewhere where I can find that?

Alternatively, if you can make a simplified version of the demo that ONLY has the form called ctlAttachments that consists of a form onto which the user can drag and drop an attachment from Windows and it will capture the path of the attachment, I'm pretty confident that I can use it "as is" and adapt it for my needs.

Thank you!
Go to the top of the page
 
JonSmith
post Jan 16 2020, 05:57 AM
Post#14


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



If you can hang on. I'll get his done for you with a proper documentation and ensure the up to date code.
Its a pretty creative workaround if I do say so myself.

Rather than replying on any external references etc, my method leverages the availability Access has natively. Access provides drag and drop functionality for attachment fields, now for many reasons its recommended you generally avoid attachment fields as they will bloat your database massively, however what I do is create a dummy table with one row and an attachment field. My code basically uses this field as a placeholder to provide the drag and drop functionality and catches whatever is dropped to it, the data is never committed to the database so you dont get any bloat.

Using this method we should be pretty future proof as its using native Access functions only.
Go to the top of the page
 
shadow
post Jan 16 2020, 08:19 AM
Post#15



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


my method leverages the availability Access has natively. Access provides drag and drop functionality for attachment fields

I didn't realize that. That definitely is creative!

It won't help me because I am still using the mdb format for a number of reasons. It might help in the future if I ever migrate to a more recent version, or it might help someone already using a more recent version.

I don't want to turn this into a discussion of why I use Access 2003 still, but as far as being "future proof", Microsoft can just as easily discontinue attachment fields as they did the ability we once had to drag and drop on Windows 7, or the long list of features they've discontinued for the past 5 versions of Access.

I am still hoping that someone can come up with a method that would be compatible with older versions.

Thanks anyway smile.gif
This post has been edited by shadow: Jan 16 2020, 08:30 AM
Go to the top of the page
 
payfast8898
post Feb 2 2020, 12:57 PM
Post#16



Posts: 411
Joined: 23-April 15
From: NY


Hey JohnSmith i was looking at the demo very cool how do i just get the path after i drag the file on. I have an older version that don't work on the newer ms access and i just need to get the path of the file after i drag it to the form.

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
shadow
post Feb 2 2020, 02:34 PM
Post#17



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


@payfast:

Do you have something that works on Access 2003 and Win 10?

Go to the top of the page
 
payfast8898
post Feb 2 2020, 03:14 PM
Post#18



Posts: 411
Joined: 23-April 15
From: NY


no not for windows 10. i came up with an alternative in access 10 and up https://www.UtterAccess.com/forum/index.php...2051642&hl= and works great but i enjoyed using the drag on to the form as well.

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
JonSmith
post Feb 10 2020, 04:30 AM
Post#19


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



QUOTE
Hey JohnSmith i was looking at the demo very cool how do i just get the path after i drag the file on. I have an older version that don't work on the newer ms access and i just need to get the path of the file after i drag it to the form.


Not possible on an older version. You need attachment fields to use drag and drop, without that there is no path to read.
You just need to update to at least Access 2007, even that is waaaay out of support so you are risking your software being inaccessible using 2003 or earlier.
Bite the bullet and upgrade man, if your customers wont, charge a premium for extended support.
Go to the top of the page
 
payfast8898
post Feb 10 2020, 08:24 AM
Post#20



Posts: 411
Joined: 23-April 15
From: NY


Sorry i think you got the wrong guy, we are using 16 and 365. I think Shadow was looking for a older version. I have an older version that will not work on the newer version of access as i stated and was just wondering if you can get the path example C:\test\test.jpg in your solution.

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    10th April 2020 - 02:11 PM