Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping

Status
Not open for further replies.

accessvbahelp

Technical User
Oct 26, 2011
24
US
This is the last of my finishing touches on this project!!!

When the approve or revise button is clicked in the database, a file will move from one location to another, I want to stop this from happening if a file already exists but I do not get an error window to pop up to tell me a file already exists, it just automatically replaces the old file with the new one. I need to create an error trapping for runtime error #58 “This file already exists” but without the error window popping up I can’t create this error trap. Can this be fixed?
 
Can this be fixed?
Which code should be fixed ????

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

And what would you want to happen when this error happens?
Give a message to the user about it? Ignore the error? Do something else?

Have fun.

---- Andy
 
Why not check if the file exists, then cancel the save if it does and provide an error message. It is normally better practice to check for existence then to use error trapping for program flow.
 
Code:
Function fcnIsFileDIR(strPath As String, Optional lngType As Long) As Integer
    On Error Resume Next
    fcnIsFileDIR = Len(Dir(strPath, lngType)) > 0
End Function
this can be called to look for a an existing file or directory like this

Code:
Call fcnIsFileDIR("c:\winnt\win.ini")
returns true if the file is found or false if not. could also be called like this

Code:
Dim intFile As Integer
intFile = fcnIsFileDIR("c:\winnt\win.ini")

If intFile = 1 Then
    'execute code if file exists
Else
    'execute for false
End If

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top