Link to home
Start Free TrialLog in
Avatar of BFanguy
BFanguyFlag for United States of America

asked on

Access 2010 drag and drop file to row on form only need relative path / filename of the file that was dragged.

I am looking for a way for a user to be able to drag and drop 1 file to a row on a form.
When the file is dropped i want to run vba code that only needs the file name of the file that was drug to the control.

I am going to prompt them asking if they want to copy the file to the record.
If yes, then in vba, i am going to copy / rename the file into a different directory and then store the new relative path/filename with the record. (Note: I don't need it as a hyperlink, just the relative path / filename )

Any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BFanguy

ASKER

Thanks pat,  I knew about the filedialog option, but was looking for a drag and drop solution within access.
Access doesn't do drag and drop natively.  You can simulate it within a form but once you go outside the Access window, you are in Windows territory and would need to use the Windows API.

Where is the file list?  is it on a form?  If so, I have seen a simulated drag and drop example but I would have to search for it.  Someone else might have it handy.
Avatar of BFanguy

ASKER

the drag and drop examples i can find are from one control to another, not from outside of access to access on a continuous form.
I have used Peter's Drag N Drop app ... and it's VERY cool.  You can download a fully functional demo to see if it can work for you:

http://www.peterssoftware.com/dd.htm

I have personally used it in a few apps ...
Peter's example only works within a form.  There is no way without using the Windows API  that you can drag from some other application.  It is a coordinates issues.  Within the form, Access knows where everything is and you can manipulate the control's Left/Top/Bottom/Right values to move them around but once you get outside of Access, HOW will you determine the coordinates?   You're going to have to drag across EVERYTHING between the starting point and the Access textbox, plus you are not referencing text so how do you propose to even get the file name from the string.  Access is a fabulous RAD program.  It can create data-centric applications with ease.  It is not a graphics program and this is a graphics problem.

Why are you fixated on dragging from some other window?  What is the problem with selecting from the common dialog?
Avatar of BFanguy

ASKER

I was wondering if i could use the TreeView ActiveX for what i needed.
Now I don't understand what you are trying to do.  I thought I did but I'm lost.  Can you post a picture of your from source and another of your to source?

When working with files, I find the standard Windows common file dialog to be the most user friendly.  It is very familiar since it pops up whenever they need to get or save a file from any compliant windows app.  Using a familiar tool always helps with creating sound interfaces.

ActiveX controls are difficult to distribute and therefore should be avoided at all costs.

If a Treeview really will solve your problem, someone has written an all VBA version that you can incorporate into your app to eliminate the DLL hell of trying to distribute the ActiveX.

The code I posted limits the selection to a single file but the dialog is capable of multi-select if that helps you.
Avatar of BFanguy

ASKER

User generated image
How would the treeview help you?
I know you can't add buttons to a subform in DS view but you can make something colorized that says select file to open the dialog.

Granted, they need to use your instance of the file dialog to pick the file rather than opening a separate instance but keystroke wise it isn't more cumbersome.

If you want to use two subforms, you can make the left one simulate the file dialog by filling it.  You would need to implement drilldown logic to keep changing the folder name.  I'm sure you could do it but it's a lot more code than what I posted.  The functions can be copied as is into any standard module in any database, as long as you set a reference to the Office library.  Then one line of code copies the name from the dialog and another line strips off the file name from the full path.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BFanguy

ASKER

Since there is no real drag and drop, i used Pat's filedialog suggestion