Check for file

esskaykay

Registered User.
Local time
Today, 04:24
Joined
Mar 8, 2003
Messages
267
I have a module called GetFile() that verifies a network connection.

Public Function GetFile()
If Dir("\\city_server\engr_files\sidewalks\2005\swk_05.mdb") = "" Then
MsgBox "Could not locate file - please verify network connection..."
Else
DoCmd.RunMacro ("macImport")
End If
End Function

If the files does not exist, it returns the MsgBox message. However, if the network connection is unavailable (i.e., unplugged), it returns Run-time error 52 > Bad file name or number.

What I want if the laptop is inadvertently unplugged, to return the MsgBox.

Thanks,
SKK
 
Code:
Public Function GetFile()
On Error Goto Err_Handler

    If Dir("\\city_server\engr_files\sidewalks\2005\swk_05.mdb") = "" Then
        MsgBox "Could not locate file - please verify network connection..."
    Else
        DoCmd.RunMacro ("macImport")
    End If

Ext_Procedure:
    Exit Function 

Err_Handler:
    Select Case Err.Number
        Case 52
            MsgBox "Could not locate file - please verify network connection..." 
    End Select
    Resume Ext_Procedure
End Function

You just need to learn about some error handling.
 
That did it. Thank you very much...

SKK
 

Users who are viewing this thread

Back
Top Bottom