My code below had been working but something I must have changed has rendered the code below invalid. I now get the msgbox error "file not found" which comes from error trap code I've included. I may not have this code setup correctly.
My textbox TaskDescrip is populated from another command button that inserts a hyperlink to a source file using the acCmdInsertHyperlink.
The button code below is supposed to take the TaskDescrip value and convert it to an I: drive path and then repopulate the TaskDescrip textbox with the hyperlink equivalent of that I: drive path/filename. I need the cmdSaveHyper to convert only the filename in the textbox regardless whether it has a path included or not. Can anyone see where I am missing the boat on this code?
Private Sub cmdSaveHyper_Click()
On Error GoTo Err_cmdSaveHyper_Click
Dim Ofile As String
Dim DestFile
Dim strFileName As String
Dim strMyHyper As String
Dim TaskHyp, RemvHyp, DestHyp As String
Ofile = Me!TaskDescrip
TaskHyp = TaskDescrip.Value 'TaskDescrip is a hyperlink value at this point
'to get just the filename from the hyperlink path in TaskDescrip
If InStr(TaskDescrip.Value, "\") > 0 Then
strFileName = Right(TaskHyp, Len(TaskHyp) - InStrRev(TaskHyp, "\"))
Else
strFileName = TaskDescrip.Value
End If
RemvHyp = Left(strFileName, Len(strFileName) - 1)
DestFile = "I:\SNL\09 - Contractor General Files\WAMS_Docs\" & RemvHyp
'to get the path
TaskHyp = HyperlinkPart(TaskDescrip, acDisplayedValue)
DestHyp = DestFile
FileCopy TaskHyp, DestHyp
're-embed hyperlink
TaskDescrip = "#" & DestHyp & "#"
Exit_cmdSaveHyper_Click:
Exit Sub
Err_cmdSaveHyper_Click:
MsgBox Err.Description
MsgBox "Make sure file is on the C Drive and try to browse file again", vbInformation, Error
Resume Exit_cmdSaveHyper_Click
End Sub
My textbox TaskDescrip is populated from another command button that inserts a hyperlink to a source file using the acCmdInsertHyperlink.
The button code below is supposed to take the TaskDescrip value and convert it to an I: drive path and then repopulate the TaskDescrip textbox with the hyperlink equivalent of that I: drive path/filename. I need the cmdSaveHyper to convert only the filename in the textbox regardless whether it has a path included or not. Can anyone see where I am missing the boat on this code?
Private Sub cmdSaveHyper_Click()
On Error GoTo Err_cmdSaveHyper_Click
Dim Ofile As String
Dim DestFile
Dim strFileName As String
Dim strMyHyper As String
Dim TaskHyp, RemvHyp, DestHyp As String
Ofile = Me!TaskDescrip
TaskHyp = TaskDescrip.Value 'TaskDescrip is a hyperlink value at this point
'to get just the filename from the hyperlink path in TaskDescrip
If InStr(TaskDescrip.Value, "\") > 0 Then
strFileName = Right(TaskHyp, Len(TaskHyp) - InStrRev(TaskHyp, "\"))
Else
strFileName = TaskDescrip.Value
End If
RemvHyp = Left(strFileName, Len(strFileName) - 1)
DestFile = "I:\SNL\09 - Contractor General Files\WAMS_Docs\" & RemvHyp
'to get the path
TaskHyp = HyperlinkPart(TaskDescrip, acDisplayedValue)
DestHyp = DestFile
FileCopy TaskHyp, DestHyp
're-embed hyperlink
TaskDescrip = "#" & DestHyp & "#"
Exit_cmdSaveHyper_Click:
Exit Sub
Err_cmdSaveHyper_Click:
MsgBox Err.Description
MsgBox "Make sure file is on the C Drive and try to browse file again", vbInformation, Error
Resume Exit_cmdSaveHyper_Click
End Sub