Option Compare Database
Private Sub Form_Load()
Me.DummyControl.SetFocus
End Sub
Private Sub DropZone_Click()
Me.DummyControl.SetFocus
End Sub
Private Sub DropZone_AfterUpdate()
Dim hLink As Hyperlink
Me.DropZone.Value = RelativeToAbsoluteHyperlink(Me.DropZone.Value)
Set hLink = Me.DropZone.Hyperlink
Me.Parent!sFilePath.Value = hLink.Address
Me.DropZone.Value = vbNullString
Me.DummyControl.SetFocus
End Sub
Public Function ExtractDirName(ByVal sPathName As String, _
Optional ByVal sDelimiter As String = "\") As String
Dim iIndex As Integer
For iIndex = VBA.Len(sPathName) To 1 Step -1
If Mid(sPathName, iIndex, 1) = sDelimiter Then Exit For
Next iIndex
If iIndex <= 1 Then
ExtractDirName = ""
Else
ExtractDirName = VBA.Left(sPathName, iIndex - 1)
End If
End Function
Public Function ExtractFileName(ByVal sPathName As String, _
Optional ByVal sDelimiter As String = "\") As String
Dim iIndex As Integer
For iIndex = VBA.Len(sPathName) To 1 Step -1
If Mid(sPathName, iIndex, 1) = sDelimiter Then Exit For
Next iIndex
ExtractFileName = VBA.Right(sPathName, VBA.Len(sPathName) - iIndex)
End Function
Public Function RelativeToAbsoluteHyperlink(ByVal sHyperlink As String) As String
Dim sTemp() As String
Dim iIndex As Integer
Dim sResult As String
If Nz(sHyperlink, "") <> "" Then
sTemp() = Split(sHyperlink, "#", , vbTextCompare)
For iIndex = LBound(sTemp) To UBound(sTemp)
If Len(sTemp(iIndex)) > 0 Then
If Left(sTemp(iIndex), 2) = ".." Then
sTemp(iIndex) = Replace(sTemp(iIndex), "/", "\")
End If
sTemp(iIndex) = RelativeToAbsolutePath(sTemp(iIndex))
End If
If iIndex = LBound(sTemp) Then
sResult = sTemp(iIndex)
Else
sResult = sResult & "#" & sTemp(iIndex)
End If
Next iIndex
End If
RelativeToAbsoluteHyperlink = sResult
End Function
Function RelativeToAbsolutePath(ByVal sRelativePath As String, _
Optional ByVal sStartPath As String = "", _
Optional ByVal sDelimiter As String = "\") As String
Dim iCount As Integer
Dim iIndex As Integer
Dim iIndex2 As Integer
Dim sFileName As String
Dim sPathName As String
Dim sResult As String
Dim sSplit() As String
Dim sSplit2() As String
Dim sTemp As String
Dim bIsCurrent As Boolean
If sStartPath = "" Then
sStartPath = Application.CurrentProject.Path
bIsCurrent = True
End If
If (Left(sRelativePath, 2) = "\\") Or _
(Mid(sRelativePath, 2, 1) = ":") Or _
(Left(sRelativePath, 5) = "http:") Or _
(Left(sRelativePath, 6) = "https:") Or _
(Left(sRelativePath, 4) = "ftp:") Or _
(Left(sRelativePath, 7) = "mailto:") Or _
(Left(sRelativePath, 7) = "callto:") Then
'Path is already absolute
RelativeToAbsolutePath = sRelativePath
Exit Function
End If
sPathName = ExtractDirName(sRelativePath, sDelimiter)
sFileName = ExtractFileName(sRelativePath, sDelimiter)
If Left(sPathName, 2) = ".." Then
'Go up
iCount = 0
sSplit() = Split(sPathName, sDelimiter, -1, vbTextCompare)
sSplit2() = Split(sStartPath, sDelimiter, -1, vbTextCompare)
For iIndex = 0 To UBound(sSplit())
If sSplit(iIndex) = ".." Then
iCount = iCount + 1
sResult = ""
For iIndex2 = 0 To UBound(sSplit2()) - iCount
If sResult <> "" Then
sResult = sResult & sDelimiter
End If
sResult = sResult & sSplit2(iIndex2)
Next iIndex2
Else
If sResult <> "" Then
sResult = sResult & sDelimiter
End If
sResult = sResult & sSplit(iIndex)
End If
Next iIndex
sResult = sResult & sDelimiter & sFileName
Else
sResult = sRelativePath
End If
If bIsCurrent = True Then
RelativeToAbsolutePath = sStartPath & sDelimiter & sResult
Else
RelativeToAbsolutePath = sResult
End If
End Function