View Full Version : Check for file


esskaykay
04-28-2005, 09:28 AM
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

modest
04-28-2005, 11:03 AM
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.

esskaykay
04-28-2005, 11:42 AM
That did it. Thank you very much...

SKK