473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Drop feature of the Hyperlink box not working on form in MS-Access

1
To give an idea of what I'm trying to achieve, I've placed the sample code (and how to try it - very easy)...
I have a MS Access form that is bound to a query in the database. I added a textbox and added a row source to a Hyperlink datafield in the query. When I open the form, it won't allow me to drop a file into the textbox.

Here's the deal. When I follow this EXACT same process on a new form, it works perfectly. That is, I open a blank form and I bind the form to some new query, let's say qryNewIdeas. Then on the blank form i add a textbox, let's say Text0. Then, when I select Text0, I go to the data tab - row source and choose the dropdown arrow to select the hyperlink field, lets say NewIdeasAddress. I click SAVE and open the form. It works PERFECTLY.

BUT, when I repeat this on an existing form (the one where I need the thing to actually work), it does nothing. It adds and changes the textbox to a hyperlink box (I note this because of the blue underlined word that appears in the box). But it won't allow me to drop files to this location.

I tried commenting out ALL of my VBA code to try to make sure that something wasn't hindering it (say in an OnLoad event) AND I've checked all of the form and control box properties and they seem to be the same in both the existing form and the test form.

I can't determine why it works on one form and not the other; Solution needed. OR Is there some better way to create the DragNDrop simulation where my users can drop a file from their desktop on to my ms-access form and I retrieve the file path?
Expand|Select|Wrap|Line Numbers
  1. 'Citation Record:
  2.  
  3. 'Kreszch68. (2012, January 12).
  4. 'Re: Re: Drag And Drop File VBA - on MrExcel.com [Web log comment].
  5. 'Retrieved April 9, 2016,
  6. 'from http://www.mrexcel.com/forum/microsoft-access/408038-drag-drop-file-visual-basic-applications.html
  7.  
  8. '**** HOW TO TRY THIS EXAMPLE
  9. 'create a simple table with just two fields, FileHyperlink (type = hyperlink) and FilePath(type = text). 
  10. 'Then create a form and place the two fields on the form. Copy this code to the form code.
  11. '
  12.  
  13. Option Compare Database
  14. Option Explicit
  15.  
  16. Private Sub FileHyperLink_AfterUpdate()
  17. Dim hlink As Hyperlink
    Me.FileHyperLink.Value = RelativeToAbsoluteHyperlink(Me.FileHyperLink.Value)
  18. Set hlink = Me.FileHyperLink.Hyperlink
  19. Me.FilePath.Value = hlink.Address
  20. Me.FileHyperLink.Value = vbNullString
  21. DoCmd.RunCommand acCmdSaveRecord
  22. End Sub
  23. Function ExtractDirName(strPathName As String, Optional strDelimiter As String = "\") As String
  24.   Dim intIndex As Integer
  25.   For intIndex = VBA.Len(strPathName) To 1 Step -1
  26.     If Mid(strPathName, intIndex, 1) = strDelimiter Then Exit For
  27.   Next
  28.   If intIndex <= 1 Then
  29.     ExtractDirName = ""
  30.   Else
  31.     ExtractDirName = VBA.Left(strPathName, intIndex - 1)
  32.   End If
  33. End Function
  34. Function ExtractFileName(strPathName As String, Optional strDelimiter As String = "\") As String
  35.   Dim intIndex As Integer
  36.   For intIndex = VBA.Len(strPathName) To 1 Step -1
  37.     If Mid(strPathName, intIndex, 1) = strDelimiter Then Exit For
  38.   Next
  39.   ExtractFileName = VBA.Right(strPathName, VBA.Len(strPathName) - intIndex)
  40. End Function
  41. Function RelativeToAbsoluteHyperlink(strHyperlink As String) As String
  42.   Dim strTemp() As String
  43.   Dim intIndex As Integer
  44.   Dim strResult As String
  45.   If Nz(strHyperlink, "") <> "" Then
  46.     strTemp() = Split(strHyperlink, "#", , vbTextCompare)
  47.     For intIndex = LBound(strTemp) To UBound(strTemp)
  48.       If Len(strTemp(intIndex)) > 0 Then
  49.         If Left(strTemp(intIndex), 2) = ".." Then
  50.           strTemp(intIndex) = Replace(strTemp(intIndex), "/", "\")
  51.         End If
  52.         strTemp(intIndex) = RelativeToAbsolutePath(strTemp(intIndex))
  53.       '  Debug.Print strTemp(intIndex)
  54.       End If
  55.       If intIndex = LBound(strTemp) Then
  56.         strResult = strTemp(intIndex)
  57.       Else
  58.         strResult = strResult & "#" & strTemp(intIndex)
  59.       End If
  60.     Next
  61.   End If
  62.   RelativeToAbsoluteHyperlink = strResult
  63. End Function
  64. Function RelativeToAbsolutePath(strRelativePath As String, _
  65.   Optional strStartPath As String = "", _
  66.   Optional strDelimiter As String = "\") As String
  67.  
  68.   Dim intCount As Integer
  69.   Dim intIndex As Integer
  70.   Dim intIndex2 As Integer
  71.  
  72.   Dim strFileName As String
  73.   Dim strPathName As String
  74.   Dim strResult As String
  75.   Dim strSplit() As String
  76.   Dim strSplit2() As String
  77.   Dim strTemp As String
  78.  
  79.   If strStartPath = "" Then
  80.     strStartPath = Application.CurrentProject.Path
  81.   End If
  82.   If (Left(strRelativePath, 2) = "\\") Or _
  83.     (Mid(strRelativePath, 2, 1) = ":") Or _
  84.     (Left(strRelativePath, 5) = "http:") Or _
  85.     (Left(strRelativePath, 6) = "https:") Or _
  86.     (Left(strRelativePath, 4) = "ftp:") Or _
  87.     (Left(strRelativePath, 7) = "mailto:") Or _
  88.     (Left(strRelativePath, 7) = "callto:") Then
  89.     'Path is already absolute
  90.     RelativeToAbsolutePath = strRelativePath
  91.     Exit Function
  92.   End If
  93.  
  94.   strPathName = ExtractDirName(strRelativePath, strDelimiter)
  95.   strFileName = ExtractFileName(strRelativePath, strDelimiter)
  96.   If Left(strPathName, 2) = ".." Then
  97.     'Go up
  98.     intCount = 0
  99.     strSplit() = Split(strPathName, strDelimiter, -1, vbTextCompare)
  100.     strSplit2() = Split(strStartPath, strDelimiter, -1, vbTextCompare)
  101.     For intIndex = 0 To UBound(strSplit())
  102.       If strSplit(intIndex) = ".." Then
  103.         intCount = intCount + 1
  104.         strResult = ""
  105.         For intIndex2 = 0 To UBound(strSplit2()) - intCount
  106.           If strResult <> "" Then
  107.             strResult = strResult & strDelimiter
  108.           End If
  109.           strResult = strResult & strSplit2(intIndex2)
  110.         Next
  111.       Else
  112.         If strResult <> "" Then
  113.           strResult = strResult & strDelimiter
  114.         End If
  115.         strResult = strResult & strSplit(intIndex)
  116.       End If
  117.     Next
  118.     strResult = strResult & strDelimiter & strFileName
  119.   Else
  120.     strResult = strRelativePath
  121.   End If
  122.  
  123.   RelativeToAbsolutePath = strResult
  124. End Function
Apr 9 '16 #1
1 1000
zmbd
5,501 Expert Mod 4TB
Would you please post the SQL for the query the form is bound to?

Please enclose the SQL in the same [CODE/] format that you used for the VBA.

thnx
-z
May 1 '16 #2

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

Similar topics

0
by: Paul | last post by:
Can anyone point me to how I would drag and drop a hyperlink from my C# application into Outlook? I can pass the URL as text, and Outlook 2003 recognizes it as a URL and activates the link,...
0
by: Chris Barnard | last post by:
Hi, I've got a form with a custom shape defined by a region. Does anyone know if it's possible to add a drop-shadow underneath the form similar to the standard windows one - with alpha blending?...
2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
3
by: rgsw | last post by:
I would like to create a drop down list in a form. When month is selected I would like information for that month only to show in form. Would I have to connect to a different table for each month? ...
3
mnemosyne
by: mnemosyne | last post by:
hi i'm trying to figure out how to have a hypertext link in a form use the information entered from a separate field in order to link to a word document EXAMPLE Link to Report is a hyperlink that...
1
by: Preet Inder | last post by:
Hi My pivot charts and pivot tables are not working no error message is there its just blank
2
by: madhu7sudan | last post by:
Hi In ASP i want to send a mail. And i am using FCK editor. In that editor if i entre www.google.com it changes to Hyperlink i.e. if i press on that link it redirected to goole home page. It...
1
by: Gaby Sandoval | last post by:
i currently use a SQL statement on my website to display a group of images (more specifically their location on the server) and links from the access database. only images that meet certain...
0
by: mpaccess | last post by:
is there a way to use tab to go from one hyperlink to another on a form in access 2003? or is there a way of setting up a comination of alt+ to select a hyperlink rather than using the mouse to...
0
by: pavanip | last post by:
Hi, I am new to Silverlight Applications. I created one media player control to play video in asp.net website.I want to drag and drop that media player control to desired place when we run the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
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...

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.