Getting absolute file paths from files draged and dropped onto a control

Ease of Use


Version tested with


Submitted by:



This will allow you to get the absolute path of a file that is dragged and dropped onto a Microsoft webbrowser control. 


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. 


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:

  1. Create a new form in access
  2. add a Microsoft ActiveX control to the form
  3. Right click on the webbrowser control and press build event
  4. if prompted select Code Builder
  5. in the coding window delete the two lines of text that are created leaving only Option Compare Database
  6. copy and paste the code from this sample to the code window
  7. change the word WebBrowser to the name of the webbrowser control on your form
  8. save all changes and view the form in normal mode
  9. drag a file onto the webbrowser control; a msgbox should appear with that files absolute path

Test the code:


Sample File:

Drag and drop file 24.87KB 

Approved by Jacob Hilderbrand

This entry has been viewed 14 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express