473,836 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a drag and drop field for files?

Seth Schrock
2,965 Recognized Expert Specialist
I'm trying to create an easy way to get references to files into my database. I want users to be able to drag and drop a file from their desktop (or anywhere else on their computer) onto a control of some kind and have the file get placed on the server with a hyperlink in the database to the file on the server. In reading stuff online, I found out that the Hyperlink data type makes it so that you can drag a file onto a textbox and it will automatically create a hyperlink to that file. My idea was then to use that hyperlink to be able to do a FileCopy to the server and then change the value in the control to be the location on the server instead of the user's PC. When tried, the hyperlink that gets added to the text box when the file is dropped onto it is not a regular file path that FileCopy can use. It starts with ... and then the file path inside pound signs and then duplicates that again. Also, it doesn't include the starting part of the file path so I can't use Left(), Right(), or Mid() functions to parse it down to a usable file path. Now I'm out of ideas.
Mar 16 '13
25 33646
5,501 Recognized Expert Moderator Expert
>>>UglyFace_n_B ad_Words<<<<<
Sometimes MS really just gets under my skin with how they do things!

OK this took me forever to figure out and haveing the distraction of the kids didn't help (well, actually it did to some degree in that they kept me from getting too deep in any one direction).

Reading thru my texts there is a base hyperlink path property that showed up in V2003 for sharepoint and other web uses.

That led me to think about the "File://" pre-pend when I'm trying to open a HTML from the local drive.

Which led me to try that in the base hyperlink path property for the database. (file... in V2010 look to the right, click on the small line of text that says... show database properties - summary tab)

When that property is not set then the path returned on a drag and drop appears to randomly be either relative or absolute; however, when I set the value to the "File://" then the path seems to always return the absolute path.

Now, because this is the home PC I haven't tried this on network files, nor have I tried this on outlook attachments.... . someone with a better understanding than I will have to handle the outlook attachments

However... because MS has really torqued my jaws on this...

Here's a function that will toggle the value from VBA.
Run the first time to set the value to the "File://"
Run a second time to clear.
It will return a "0" if all went well
It will return a "1" and popup a message block if any unexpected errors occured.

This is a modification of the code I use to set custom properties for my databases.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Public Function fnc_SetorClearHyperlinkBase()
  5.     Dim zdb As DAO.Database
  6.     Dim zdoc As DAO.Document
  7.     Dim zprp As DAO.Property
  8.     Dim zstrPathApp
  9.     Dim zstrErr As String
  10.     '
  11.     'Set for error trap
  12.     On Error GoTo zErr_Handler
  13.     '
  14.     'set the base hyperlink file (could use the current database root)
  15.     'use File:// to force file condition
  16.     zstrPathApp = "File://"
  17.     '
  18.     'Set the pointers to the current database and properties collection
  19.     Set zdb = CurrentDb
  20.     '
  21.     'Now, here's the stumbling block... I was using just "Summary" as it shows
  22.     'on the tab in the dialog...
  23.     'Then reading thru my references, there was an example to set the title in
  24.     'summary... and the value was, "SummaryInfo"
  25.     'once I found that... this almost wrote itself!
  26.     '
  27.     Set zdoc = zdb.Containers("Databases").Documents("SummaryInfo")
  28.     Set zprp = zdoc.Properties("Hyperlink base")
  29.     '
  30.     'If we didn't error out on 3270 then remove the Hyperlink Base from the properties collection
  31.      zdoc.Properties.Delete ("Hyperlink base")
  32.     '
  33.     'return zero if no error
  34.     fnc_SetorClearHyperlinkBase = 0
  35.     '
  36. z_returnfromerror:
  37.     '
  38.     'clean up
  39.     Set zprp = Nothing
  40.     Set zdoc = Nothing
  41.     Set zdb = Nothing
  42. Exit Function
  43. '
  44. zErr_Handler:
  45.     If Err.Number = 3270 Then
  46.         '
  47.         ' property not found in the collection so create it and add
  48.         Set zprp = zdoc.CreateProperty("Hyperlink base", dbText, zstrPathApp)
  49.         zdoc.Properties.Append zprp
  50.         Resume z_returnfromerror
  51.     Else
  53.         zstrErr = "Error: " & Err.Number & ": " & Err.Description
  54.         MsgBox zstrErr, , "fnc_SetHyperlinkbase"
  55.         fnc_SetorClearHyperlinkBase = 1
  56.         Resume z_returnfromerror
  57.     End If
  58. End Function
Insert a new module, copy the above to it, compile, and thumb nose at MS for not making this simpler.

I use the dialog box and ask the user to find the file and then store that location in a normal text field instead of all of this hyperlink stuff... took the advise from AB website about this (where I link you to in my first post).
Mar 17 '13 #11
2,322 Recognized Expert Moderator Top Contributor
There are certain advantages to using Hyperlink. The major is that they are not dependent on a dll or active X control.

The downside is they must be bound, since the control is still just a textbox, and the behavior of the control depends on it being bound to hyperlink type field. If anyone has a way to make a unbound control that works in the same way as a control bound to a hyperlink field I would like to know.

Any way, I cooked up a sample db (2003 format) that illustrates how documents can be dragged onto a listview control, and saved from there.
Hope that helps.
Mar 17 '13 #12
8,834 Recognized Expert Expert
You can select a single or multiple Files from Windows Explorer, and then Drop them into a TreeView Control. The File Names, complete with Absolute PATHs, then become single Nodes under a Root Node. Once the Drag-N-Drop process has completed all the Nodes can be referenced and the Files copied to a pre-determined PATH on the Server. Clicking on any Node of the TreeView can then Open the associated File on the Server. Nothing is stored within the Database.
Mar 17 '13 #13
2,322 Recognized Expert Moderator Top Contributor
Hi ADezii. I just tried that and nothing happens. I don't know if any of the default settings need to be modified. Sure I could code this into the treeview since that also supports OLE drag and drop, but you saying this behavior is built into the treeview somehow?
Mar 17 '13 #14
Seth Schrock
2,965 Recognized Expert Specialist
@Smiley The file path isn't getting put into the table. Is it supposed to or would you recommend having the manual hyperlink append the file path to it?

@ADezii I would love a tree view as I plan on grouping files by type, so having the built it grouping would be great. However, I'm not very familiar with Treeview controls (or any ActiveX control for that matter). Do you have an example, or a book/website that I could read to learn about it?
Mar 17 '13 #15
5,501 Recognized Expert Moderator Expert
With the solution I've given in post#11 one doesn't need an external reference library nor anything beyond the current core VBA. This forces the absolute path to be stored in the hyperlink field and the property is easily toggled from the "set" state back to default.

I love the fact that there are so many ways to work around this; however, I'm a great advocate of not using more external library references than absolutly needed to get a task done... even if they are nicer from a GUI stand point.

As it stands now, with V2013 around the corner, Win7-67bit OS becoming the mainstream with the 64Bit office soon to follow, Win8 and possibly another OS release within the year - using ActiveX controls designed for 32bit is somewhat scary and in fact in post #8 TheSmileyCoder points out just one such break. And we never know when MS is going to mess up another Kill Bit in an Office or OS security update.
Mar 17 '13 #16
8,834 Recognized Expert Expert
@Seth Schrock
Seth, as soon as I get a chance I'll see if I can put a small Demo together for you.
Mar 18 '13 #17
Seth Schrock
2,965 Recognized Expert Specialist
@ADezii That would be great.

@Z From where would I call your function? I assume that the textbox would still need bound to a hyperlink field?
Mar 18 '13 #18
2,322 Recognized Expert Moderator Top Contributor
Seth Schrock
@Smiley The file path isn't getting put into the table. Is it supposed to or would you recommend having the manual hyperlink append the file path to it?
No, the filepath is not meant to be put into the table. The setup I used in the demo is a semi-relative path. This means you can move the document storage folder without breaking the application. A copy is placed into the storage folder, subdivided by case number.
Mar 18 '13 #19
8,834 Recognized Expert Expert
I created a demo for you that will enable you to dynamically Drag-N-Drop any File(s) into a TreeView Control.
  1. Open the Demo and click on the Explorer Command Button.
  2. Select any File/Group of Files, hold down the SHIFT Key, then DragNDrop into the TreeView Window.
  3. When finished, expand the Main Node to view all the Files that have been dropped, minus the extensions. The Absolute PATHs to each File are the actual Display Values for that Node.
  4. Click on any File Name to see info related to that File.
  5. Critical Code is contained in the OLEDragDrop() Event of the TreeView Control.
  6. I have not tried this, but once you are done you can iterate through all the Nodes and perform a Bulk Copy Operation to your Server.
  7. The File Names/PATHs will not persist in the TreeView, so at some point they will need to be stored internally.
  8. Each Node/File can now be opened from the TreeView via ShellExecute().
  9. Any questions please feel free to ask.
Attached Files
File Type: zip DragNDropDemo.zip (16.2 KB, 2302 views)
Mar 18 '13 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in field 1 to field 3, then field 2 text and field 3 move to field 1 and field 2. I add the new order of text into an array so when the onDragEnd event
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
by: Qingdong Z. | last post by:
I have a VS.NET windows application which use drag-drop feather. It works fine when application start, but stops working after application run one or two days. The application is related to Video process, CPU/Memory extensive. The drag-drop is in a new windows form. It drags from TreeView Control to other control in the same form. It cannot trigger ItemDrag event of TreeView after drag-drop feather die. Can you give me any idea? Thanks.
by: Nathan | last post by:
I'm working for the first time with the DoDragDrop method. I've got almost everything worked out, but I need some help with the last bit. There are two listboxes on my form, lstGroups and lstStudents. I want to be able to drag a name from lstStudents and drop it on one of the names in lstGroups to move it to that group. I've got the dragging part working; it's just the dropping that isn't there yet. I'm working with what I can find...
by: Robin Tucker | last post by:
I've implemented an IDataObject interface around one of my classes in order to facilitate drag/drop from my application into explorer. What I want to do is allow the user to select a series of data objects in my application and to drag/drop them onto explorer for explorer to create files of them. Is this possible, or will I just have to stick with an explicit "Export" method in my program?
by: Brian Henry | last post by:
I haven't worked much with drag/drop but I am trying to make a form that accepts files to drug onto it from explorer and droped and have the form know the full path and file name of the files dropped onto it.. does anyone have any examples of this? thanks
by: .Netter | last post by:
the user of my app should be able to drag an object (e.g. a file) out of my app into another folder or another app. everywhere i found information how to drag n drop objects(files) from one control to another control in the same application but nowhere i found a hint how to drag objects (files) out of an app and drop them into another one. is someone out there who know how to do that? thanks for your help.
by: Nick | last post by:
Hi, I am developping an app using managed C++. I want to be able to do a drag drop from the app to windows explorer. The files to be dropped onto explorer do not exist yet, the files are to be created by the app when the user does the drop into explorer. I have done some searches and found COleDataSource::DelaySetData could be useful but this is MFC and I can't find the equivalent in .NET.
by: Mukesh Agarwal | last post by:
Hi, I am developing a windows application, in which I am giving two options to the user for the file selection. 1. Open File Dialog 2. Drag/ Drop Now I want that the user can Drag/Drop files from the browser which opens through Open File Dialog. This is not a default feature.
by: radhikams | last post by:
Hi I want to create a drag drop tool box using javascript... Can anyone please guide me in this regard Thanks
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.