Drag and Drop File Name from Windows Explorer into Access Form Textbox

J

John

I am looking for VBA code that will work with Access 2003 to enable
dragging and dropping a file/folder name from Windows XP Explorer into
an Access form's text box. This is a common functionality that most
Windows programs have, so I'm suprised it's not easier to implement in
Access/VBA.

Through Google, I found two VB6 examples and one VBA example on the
Access Web written by Dev Ashish. The VB6 examples used loops to keep
checking for the drag-drop Windows event and prevented my form from
loading. Dev's code looked much better, but it didn't work in Accesss
2003. It looks like it was written prior to Access 2000. The link to
Dev's code is here:
http://www.mvps.org/access/api/api0032.htm
I successfully use many other API calls in my project, but trying to
debug Dev's code is way over my head.

Dev's code refers to a class module named "AddrOf" that is available
here: http://www.trigeminal.com/lang/1033/codes.asp?ItemID=19#19
However, this module has errors under Access 2003 when it runs, one of
which says a DLL file is missing.

VBA under Access 2003 has a built-in function, "AddressOf", that
should accomplish the same thing as the older "AddrOf" class module,
but I can't seem to get it to work. When I try using the "AddressOf"
function in Dev's code, it compiles fine, but when it runs, Access
2003 crashes back to the desktop.

If anyone has VBA code that will allow dragging and dropping
file/folder names from Windows explorer into a form's textbox/listbox,
would you please be kind enough to provide me with the code, or a link
to the code.

Thanks !
 
D

Douglas J. Steele

What did you change the code to? Make sure you don't have the AddrOf class
module, and try

Sub sHook(Hwnd As Long, _
strFunction As String)
lpPrevWndProc = apiSetWindowLong(Hwnd, _
GWL_WNDPROC, _
AddressOf strFunction)
End Sub
 
R

Ron Weiner

I have successfully used Dev's code in an Access 2K mde running in a variety
of Access installs from 2K to 2003. I don't think anyone has attempted
using the application in 2007, but I suspect it will work there too. If
memory serves I had to use a Subform as the "Drop" container. Again if
memory serves Dev's code needs to be hooked up to something with a valid
Hwnd. In Access, controls do not have a full time valid Hwnd (controls only
have a Hwnd when they have the focus), but Forms do. I made the "Drop" form
a subform to my main form and hooked everything up in the form open event,
and un-hooked it in the form unload event.

AddressOf has been part of Access since Access 2k.

This code has been in production for at least 2 years now with no reports of
problems. It is used to attach external files (pdf's, tiff's, word doc's,
etc.) to various database records. Using this interface for making the
attachments was not my idea, it was a customer request (OK a demand then).
I lost a fair amount of hair, and rebooted my machine many times before I
got it right.

Ron W
 
G

google-post

I have successfully used Dev's code in anAccess2K mde running in a variety
ofAccessinstalls from 2K to 2003.  I don't think anyone has attempted
using the application in 2007, but I suspect it will work there too. If
memory serves I had to use a Subform as the "Drop" container.  Again if
memory serves Dev's code needs to be hooked up to something with a valid
Hwnd.  InAccess, controls do not have a full time valid Hwnd (controls only
have a Hwnd when they have the focus), but Forms do.  I made the "Drop" form
a subform to my main form and hooked everything up in the form open event,
and un-hooked it in the form unload event.

AddressOf has been part ofAccesssinceAccess2k.

This code has been in production for at least 2 years now with no reports of
problems.  It is used to attach external files (pdf's, tiff's, word doc's,
etc.) to various database records.  Using this interface for making the
attachments was not my idea, it was a customer request (OK a demand then).
I lost a fair amount of hair, and rebooted my machine many times before I
got it right.

Ron W











- Show quoted text -

Is it also possible to drag a windows filename FROM Access to
Explorer? I haven't been able to locate anything that says it is
possible. Is it as simple as copying the correct (filename)
information to the clipboard -- or much more involved?

Thanks,
 
R

Ron Weiner

I haven't the slightest idea about how to get this working. Perhaps there
is another way around this. What exactly are you trying to accomplish?

Is it also possible to drag a windows filename FROM Access to
Explorer? I haven't been able to locate anything that says it is
possible. Is it as simple as copying the correct (filename)
information to the clipboard -- or much more involved?

Thanks,
 
G

google-post

I haven't the slightest idea about how to get this working.  Perhaps there
is another way around this.  What exactly are you trying to accomplish?

Is it also possible to drag a windows filename FROM Access to
Explorer?  I haven't been able to locate anything that says it is
possible.  Is it as simple as copying the correct (filename)
information to the clipboard -- or much more involved?

Thanks,

I have a database that holds filepath/filename information. I would
like to be able to 'drag' that file information over to another
application that accepts filenames. In this case, it is for something
called "Virtual DJ". When you drop a file (from Explorer) onto
Virtual DJ, the file is processed differently depending on whether you
drop on the left or right side of the program -- so it isn't as simple
as just passing the filename to the program.
 
R

Ron Weiner

I can think of only two ways.

From Access Shell out to explorer with the full pathname to the folder that
contains the file(s) you want to drop on Virtual DJ. Then drag em from
explorer on to Virtual DJ directly from explorer. Use Access help to get
additional info on the Shell Command.

From VB. Yup might be time to create a whole new interface to your Access
database that does support Drag Drop.

Sorry :-(

Ron W
I haven't the slightest idea about how to get this working. Perhaps there
is another way around this. What exactly are you trying to accomplish?

Is it also possible to drag a windows filename FROM Access to
Explorer? I haven't been able to locate anything that says it is
possible. Is it as simple as copying the correct (filename)
information to the clipboard -- or much more involved?

Thanks,

I have a database that holds filepath/filename information. I would
like to be able to 'drag' that file information over to another
application that accepts filenames. In this case, it is for something
called "Virtual DJ". When you drop a file (from Explorer) onto
Virtual DJ, the file is processed differently depending on whether you
drop on the left or right side of the program -- so it isn't as simple
as just passing the filename to the program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top