Hi guys,
Just want to check to see if a text file exists. If it does, then open it. If it doesnt, display a message.
Have written the following code. Wondered how I can use the FileSystemObject to actually open the text file rather than using the Application.FollowHyperlink.
Still learning VBA so just want to make sure that I am coding efficiently.
Note: I have just hacked the code out of other modules I have found by searching. Open to any better suggestions.
Thanks
BF
Just want to check to see if a text file exists. If it does, then open it. If it doesnt, display a message.
Have written the following code. Wondered how I can use the FileSystemObject to actually open the text file rather than using the Application.FollowHyperlink.
Still learning VBA so just want to make sure that I am coding efficiently.
Code:
Private Sub CmdIPConfig_Click()
On Error GoTo Err_CmdIPConfig_Click
Dim fso As Object
Dim stFileName As String
stFileName = "\\ServerName\Directory\SubDirectory" & Me!Parent!Equipment_Identifier & ".txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(stFileName) Then
Application.FollowHyperlink (stFileName) 'if text file exists then open it
Else
MsgBox "IP Config File Does Not Exisit", vbOKOnly, "Error: Unable To Locate File" 'else text file does not exist. display message to a user
End If
Exit_CmdIPConfig_Click:
Exit Sub
Err_CmdIPConfig_Click:
MsgBox Err.Description
Resume Exit_CmdIPConfig_Click:
End Sub
Note: I have just hacked the code out of other modules I have found by searching. Open to any better suggestions.
Thanks
BF