Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

959 views
Skip to first unread message

John

unread,
Apr 30, 2008, 4:52:40 PM4/30/08
to
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 !

Douglas J. Steele

unread,
Apr 30, 2008, 5:26:55 PM4/30/08
to
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


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"John" <azgtr...@yahoo.com> wrote in message
news:tumh14tu1rs52lqvp...@4ax.com...

Ron Weiner

unread,
Apr 30, 2008, 8:18:56 PM4/30/08
to
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

"John" <azgtr...@yahoo.com> wrote in message
news:tumh14tu1rs52lqvp...@4ax.com...

googl...@mp3-boss.com

unread,
May 28, 2008, 2:54:21 AM5/28/08
to
On Apr 30, 8:18 pm, "Ron Weiner" <rweineratworksritedotcom> wrote:
> 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
>
> "John" <azgtrpla...@yahoo.com> wrote in message
>
> news:tumh14tu1rs52lqvp...@4ax.com...
>
>
>
> >I am looking for VBA code that will work withAccess2003 to enable
> > dragging and dropping afile/foldernamefromWindowsXPExplorerinto
> > anAccessform's text box.  This is a common functionality that most
> >Windowsprograms 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
> >AccessWeb written by Dev Ashish.  The VB6 examples used loops to keep
> > checking for thedrag-dropWindowsevent 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 toAccess2000.  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 underAccess2003 when it runs, one of

> > which says a DLLfileis missing.
>
> > VBA underAccess2003 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 fromWindowsexplorerintoa form's textbox/listbox,

> > would you please be kind enough to provide me with the code, or a link
> > to the code.
>
> > Thanks !- Hide quoted text -
>
> - 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,

Ron Weiner

unread,
May 28, 2008, 7:06:00 PM5/28/08
to
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?

googl...@mp3-boss.com

unread,
May 28, 2008, 8:51:29 PM5/28/08
to

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.

Ron Weiner

unread,
May 28, 2008, 10:34:12 PM5/28/08
to
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
<googl...@mp3-boss.com> wrote in message
news:cbdc041d-6805-4441...@59g2000hsb.googlegroups.com...

0 new messages