Access
Getting absolute file paths from files draged and dropped onto a control
Ease of Use
Intermediate
Version tested with
2007
Submitted by:
Movian
Description:
This will allow you to get the absolute path of a file that is dragged and dropped onto a Microsoft webbrowser control.
Discussion:
I discovered this setup while building a system that will allow files to be imported and stored directly into an SQL table specifically in a VARBinary(Max) field. I needed an easy method for users to select what files they wanted to import. I setup a standard windows open file dialogue but this felt a little clumsy and took too many clicks and too much time so I decided to provide drag and drop support allowing users to drag a file onto the form to import it into the database.
Code:
instructions for use
Option Explicit 'You will need to change WebBrowser in the sub name to the name of the webbrowser activeX Control that you have placed on your form. Private Sub WebBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) 'display the file path associated with the file that was dragged onto the webbrowser control msgbox "File Path:" & URL 'we have the address of the file so prevent the browser control from displaying the contents of the file if its an image or similar. Cancel = True End Sub
How to use:
Test the code:
Sample File:
Drag and drop file paths.zip 24.87KB
Approved by Jacob Hilderbrand
This entry has been viewed 20 times.
Please read our Legal Information and Privacy Policy Copyright @2004 - 2020 VBA Express