UtterAccess.com
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 Form In Access 2013 On Windows 10 Issue, Access 2016    
 
   
ktesler
post Nov 23 2018, 05:59 PM
Post#1



Posts: 2
Joined: 23-November 18



I have an Access form that allows for a drag and drop feature where you can take a file from the desktop or another folder and drag it onto the access form and it will load the path of the file in a subform. You have the option to delete the path or engage a transporter which moves the file to a share drive on a server in a specific folder that is tied to a job number (referenced in a text field in the form). This works great on the original Windows 7 with Access 2010. We are in the process of updating the computers to Windows 10 64-bit professional and Office 2016 32-bit. I have found a workaround to get the drag and drop feature to work but it is a bit cumbersome. It involves clicking a few times first in the access form and then dragging the file over. I am wondering if it has to do with the max calls count that engages the "hook" to grab a dropped file. I saw that there was a posting many years back on this forum for this DDI_MAXCALLS (http://www.UtterAccess.com/forum/index.php?showtopic=2008220) and I am wondering if any one on this thread or anyone reading this has any ideas on how to fine tune my form in Windows10 on Access 2016 to get it to work fluidly?

The area of interest in the code is listed below. I am also including the entire module. I appreciate your thoughts on this and look forward to your replies. Thank you in advance for your help.

'If you experience occasional times where you drop files
'but they do not register, set the DDH_MAXCALLS constant
'to a higher number. In Access 2010 in particular this
'number seems to want to be set around 50 or so for
'it to work every time. You might need to go higher


Const DDH_MAXCALLS = 150
Static intCallCount As Integer

Here is the entire module:

Option Compare Database
Option Explicit

'basDragDrop
'2011-09 jl

Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long _
) As Long

Private Declare Sub DragAcceptFiles _
Lib "shell32.dll" _
(ByVal hWnd As Long, _
ByVal fAccept As Long)

Private Declare Sub DragFinish _
Lib "shell32.dll" _
(ByVal hDrop As Long)

Private Declare Function DragQueryFile _
Lib "shell32.dll" Alias "DragQueryFileA" _
(ByVal hDrop As Long, _
ByVal iFile As Long, _
ByVal lpszFile As String, _
ByVal cch As Long _
) As Long

Private Declare Function CallWindowProc _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal msg As Long, _
ByVal wparam As Long, _
ByVal lparam As Long _
) As Long

Const GWL_WNDPROC As Long = -4
Const GWL_EXSTYLE = -20

Const WM_DROPFILES = &H233

Const WS_EX_ACCEPTFILES = &H10

Private currFrm As Access.Form 'reference to the Form currently
'hooked to the callback. This
'is required to pass the dropped
'files to the form
Private currHwndFrm As Long 'handle to the currently hooked form
'this is used to verify there isn't
'two forms hooked at the same time
'(for example overlapping controls
'where the mouse jumps from one
'to the other)
Private prevWndProc As Long 'handle to the window's previous
'WindowProc. This is only set while
'currHwndFrm is valid

Private hookOn As Boolean


Public Function DragDropInitForm(hWndFrm As Long)
'inits the form for drag/drop
Dim lExStyle As Long

'get the current extended window style
lExStyle = GetWindowLong(hWndFrm, GWL_EXSTYLE)
'add the flag for accepting dragged files
lExStyle = lExStyle Or WS_EX_ACCEPTFILES
'set the new extended window style
SetWindowLong hWndFrm, GWL_EXSTYLE, lExStyle

'register the form for drag/drop acceptance
DragAcceptFiles hWndFrm, True

End Function


Public Function DragDropSetHook(hookOn As Boolean, hWndFrm As Long)
'toggles the hook on or off
If hookOn Then
dragDropHookOn hWndFrm
'Debug.Print "HookOn"
Else
dragDropHookOff
'Debug.Print "HookOff"
End If
End Function

Public Function DragDropCallback( _
ByVal hWnd As Long, _
ByVal msg As Long, _
ByVal wparam As Long, _
ByVal lparam As Long _
) As Long
'callback for drag/drops

'as in all callbacks, we're screwed if there's an error
'and need to be absolutely certain this procedure will
'exit
On Error Resume Next

'We want to turn this hook off as soon as possible after
'the files are dropped, otherwise it clogs up the rest
'of the project operations. It just so happens that the
'MouseMove event for a control accepting the dropped files
'fires exactly one time when the files are physically
'dropped on the form - that one time is where this hook
'is turned on, so it's almost a safe bet that we can
'turn this directly back off as soon as it's called.
'
'If you experience occasional times where you drop files
'but they do not register, set the DDH_MAXCALLS constant
'to a higher number. In Access 2010 in particular this
'number seems to want to be set around 50 or so for
'it to work every time. You might need to go higher


Const DDH_MAXCALLS = 150
Static intCallCount As Integer

If msg <> WM_DROPFILES Then
'the hWnd parameter passed to this function by the OS is
'the handle to the form that was hooked. If the message
'is not for a file drop, we'll send the message to that
'form's standard message procedure
CallWindowProc ByVal prevWndProc, _
ByVal hWnd, _
ByVal msg, _
ByVal wparam, _
ByVal lparam
Else
'we have a file drop, handle that
dragDropQueryFiles wparam
End If

'check the callcount and unhook if required
intCallCount = intCallCount + 1
If intCallCount >= DDH_MAXCALLS Then
intCallCount = 0
DragDropSetHook False, hWnd
End If

End Function


Private Sub dragDropQueryFiles(hDrop As Long)
'passes a semicolon delimited list of the dropped
'files to the currFrm.DragDropFiles() sub

Const MAX_PATH = 255
Dim ret As String 'function return
Dim s As String 'temp/various
Dim Icount As Integer 'count of files dropped
Dim iPathLen As Integer 'length of the current path
Dim I As Integer 'temp/various

'get the count of files dropped
s = String(MAX_PATH, 0)
Icount = DragQueryFile(hDrop, &HFFFFFFFF, s, Len(s))

'iterate the filecount and build the return
For I = 0 To Icount - 1
s = String(MAX_PATH, 0)
iPathLen = DragQueryFile(hDrop, I, s, MAX_PATH)
ret = ret & ";" & Left(s, iPathLen)
Next I

DragFinish hDrop

currFrm.DragDropFiles Mid(ret, 2)

End Sub


Private Function dragDropHookOn(hWndFrm As Long)
'turns the callback on
If hookOn Then Exit Function
'set the current form and handle for later use
currHwndFrm = hWndFrm
Set currFrm = dragDropGetFrmFromHWnd(hWndFrm)
'use SetWindowLong to set the new callback address
'and return the previous callback address to prevWndProc
prevWndProc = SetWindowLong(hWndFrm, GWL_WNDPROC, AddressOf DragDropCallback)
hookOn = True
End Function

Private Function dragDropHookOff()
'turns the callback off

'set the window's callback address to it's previous value
SetWindowLong currHwndFrm, GWL_WNDPROC, prevWndProc
'clear the window and callback settings until next callback init
prevWndProc = 0
currHwndFrm = 0
Set currFrm = Nothing
hookOn = False
End Function


Private Function dragDropGetFrmFromHWnd(hWnd As Long) As Access.Form
'retrieves a form reference from the form's handle
'this reference is later used to call the form's procedure and pass
'it the dropped file list
Dim frm As Access.Form
For Each frm In Access.Forms
If frm.hWnd = hWnd Then Exit For
Next frm
Set dragDropGetFrmFromHWnd = frm
End Function
Go to the top of the page
 
June7
post Nov 23 2018, 11:53 PM
Post#2



Posts: 1,318
Joined: 25-January 16
From: The Great Land


Might need to use PtrSafe in the API function declarations although I would expect an error message when executing code. Review https://docs.microsoft.com/en-us/office/cli...sions-of-office
This post has been edited by June7: Nov 24 2018, 12:16 AM

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
cheekybuddha
post Nov 24 2018, 03:50 AM
Post#3


UtterAccess Moderator
Posts: 12,625
Joined: 6-December 03
From: Telegraph Hill


Hi,

I tried your code last night and couldn't get it to do anything (Win10 (64bit) + Acc2007 (32bit))

It appears you are having similar issues as mentioned here

I can't see how adding LngPtr declarations would help since my Access is 32bit, but it might be worth a try, but I suspect Win10 is using a different API altogether.

shrug.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
isladogs
post Nov 24 2018, 05:01 AM
Post#4


UtterAccess VIP
Posts: 2,248
Joined: 4-June 18
From: Somerset, UK


I've just tested this in Windows 10 using both Access 2010 32-bit and Access 365 version 1812

In Access 2010, I can drag file names (not paths) onto the form as OLE images but only when the form is in design view.

Attached File  DragNDrop.PNG ( 53.12K )Number of downloads: 18


As the Access file size has increased significantly, the file is obviously now attached to the database

Using Access 365, the OLE image created doesn't show the file name. Is that what you meant?
Reopen in Access 2010 & the file name is shown as part of the OLE image

Not sure I see the point of this however. Perhaps I'm missing something.
Could you upload a stripped down copy of your db to illustrate the idea

PtrSafe is only needed for 64-bit Access though if you have 2010 or later, adding it in 32-bit Access won't do any harm
This post has been edited by isladogs: Nov 24 2018, 05:01 AM

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
payfast8898
post Nov 24 2018, 10:11 AM
Post#5



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


I also used that method for years but couldn't make it work very well on the newer access so I switch to make my own drop box kind of think where I open a file and drag a image or pdf etc. in and my access project grabs the file path for me to do what ever I want with it. it works awesome this way here are some pictures of what it looks like as I was building it in another post. https://www.UtterAccess.com/forum/index.php...2051308&hl=

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
isladogs
post Nov 24 2018, 10:22 AM
Post#6


UtterAccess VIP
Posts: 2,248
Joined: 4-June 18
From: Somerset, UK


I wouldn't use the method I showed in any circumstances as I don't like using either OLE or attachment fields due to file bloat.
Your scanner utility looks interesting. Did you ever upload it as an example app for others to look at?

For viewing external files, I just browse to the file location and save the path to an Access table.
Then view the list of files on a form using a listbox or combobox
If the files are images, open using an image control.
For other files, either open externally using the default file handler e.g. Word, Excel etc or view within Access using an ActiveX web browser control.
Both are very straightforward.

Not sure what the advantages of drag and drop might be.


--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
payfast8898
post Nov 24 2018, 11:09 AM
Post#7



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


sorry probably didn't explain my program. I use this for many application however the main one is medical billing. I drop the file into my program, I can brows, scan, take a picture or drop into a folder to get the path, after I get the path my programs renames the image and index's it under the patients id. it moves the image to another folder, not import them into access, just the new path were it is stored with a new file name. then under the patients name I can view the file the same way as you said with image control. This way there is no bloating. I can't leave the images laying all over the place for many reasons so dragging them is faster than browsing plus I can drag a lot at a time. then move them so there is not two copies on the system, I do have the option to copy also. we have to do hundreds of images a day so has been the fastest way I can find. if they come in through email they can just drag them from the email into the folder and then move them being indexed under the patient/client name.

I have not had a chance to take it out of my application to make a stand alone but I will try to get something together if there is any interest in it.

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
isladogs
post Nov 24 2018, 11:39 AM
Post#8


UtterAccess VIP
Posts: 2,248
Joined: 4-June 18
From: Somerset, UK


I think it could be of interest to others. It's certainly not an approach I've ever used.
Good luck with fixing your current issue

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
payfast8898
post Nov 24 2018, 11:46 AM
Post#9



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


ok will see what I can do the other issue I figured out a ways back but thanks.

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
payfast8898
post Nov 24 2018, 02:21 PM
Post#10



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


ok here is a demo on my Fastdrop it may have more than you need but I didn't have time to file it down too much.

use the whole folder and subfolders

there is a load defaults location for the current directory under the setup button hit that to use the folders included. you can change them to what ever you want.

you have to Add the Reference Microsoft Scripting Runtime. You do not need this for the fast drop to work I use it to delete empty folders that may get left behind if someone crashes or closes out for some reason.

I left an image in the drop box to play with if you need it.






Attached File(s)
Attached File  Fastdrop3.JPG ( 104.5K )Number of downloads: 19
Attached File  FastDrop.zip ( 605.67K )Number of downloads: 38
Attached File  Clients.JPG ( 71.65K )Number of downloads: 8
Attached File  FastDrop1.JPG ( 99.88K )Number of downloads: 7
Attached File  Fastdrop2.JPG ( 132.7K )Number of downloads: 9
Attached File  Fastdrop4.JPG ( 147.07K )Number of downloads: 12
 

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
shadow
post Nov 25 2018, 10:26 AM
Post#11



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


@ktesler:

This is something I've been having trouble with for about a year now and I'm hoping someone will find a solution.

Based on your post, I played around with the DDH_MAXCALLS and I found that when set to about 300, it kind of works. When I say kind of:

- on one computer using Win 10 it sometimes works perfectly, sometimes you have to do the drag and drop more than once for it to trigger. Within a few seconds you are able to click DONE or CANCEL
- on another computer using Win 10 it takes dragging and dropping twice to trigger but then the control freezes up and no amount of waiting allows you to click done or cancel.

I don't know if this information helps anyone but I thought I'd share my findings.
Go to the top of the page
 
payfast8898
post Nov 25 2018, 10:58 AM
Post#12



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


Sorry I forgot to add a query to change the image number. new update should do that for you.
Attached File(s)
Attached File  FastDrop__2_.zip ( 622.89K )Number of downloads: 36
 

--------------------
"When a collection of Brilliant minds, hearts and talents come together...
Expect a masterpiece"
Go to the top of the page
 
daolix
post Nov 28 2018, 09:42 AM
Post#13



Posts: 13
Joined: 29-September 16



QUOTE (ktesler)
We are in the process of updating the computers to Windows 10 64-bit professional and Office 2016 32-bit


If you use "Office 32 bit", you could use a "Listview" instead of the Apia calls.
Go to the top of the page
 
ktesler
post Nov 29 2018, 10:19 PM
Post#14



Posts: 2
Joined: 23-November 18



I am attaching a test database with the form in question. I can drag and drop a pdf without any issue on Windows 7 64-bit with Office 2010 professional 32-bit. I can't seem to get it to work at all on this test database with drag and drop of a pdf, even with my workaround that I mentioned above, with clicking in the white textbox area once, then double-clicking in the yellow area twice, and finally dragging the pdf over to the white text box area. I am using Windows 10 64-bit with Office 2016 32-bit. I appreciate your thoughts on this.
Attached File(s)
Attached File  drag_drop.zip ( 245.85K )Number of downloads: 45
 
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    9th April 2020 - 05:53 AM