Dale Logan
asked on
Pleasant message as alternative to RunTime Error
A few months ago an EE expert helped me with some code to establish a link to a file stored in a network folder. I don't have access to the folder, but some of the users have been receiving a runtime error 52: 'Bad file name or number'. No idea what that means. As an alternative to that message, I was thinking it might be better to give them a message box with a better explanation. Since someone helped me with the code, I don't know exactly what each line is doing. Would appreciate any help or suggestions.
Thanks, Dale
Thanks, Dale
Public Function Relink()
Dim str As String, path As String, fname As String, tbl As String, strlnk As String, str1 As String, str2 As String
Dim l1 As Integer, l2 As Integer
Dim db As DAO.Database
fname = "stocklist.csv"
path = "\\000.00.00.00\Forecast"
tbl = "Stocklist"
str = path & "\" & fname
If Dir(str) & "" = "" Then
path = "e:\tmp"
str = path & "\" & fname
If Dir(str) & "" = "" Then
MsgBox "File not found", vbOKOnly
Exit Function
End If
End If
Set db = CurrentDb
strlnk = db.TableDefs("Stocklist").Connect
l1 = InStr(1, strlnk, "DATABASE") + 8
str1 = Left(strlnk, l1)
str2 = Mid(strlnk, l1 + 1)
l2 = InStr(1, str2, ";")
If l2 = 0 Then
str2 = path
Else
str2 = path & Mid(str2, l2)
End If
db.TableDefs(tbl).Connect = str1 & str2
db.TableDefs(tbl).RefreshLink
Set db = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.