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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for existing file, then killing it

Status
Not open for further replies.

cammi

Programmer
May 3, 2001
13
US
I am trying to get this module to work within my Access2000 macro and it works the first time, however, if I physically delete the acadian.che file (for testing purposes), then I never can get to the part where I need to rename to acadian.txt once I add pass the acadian.che file. I believe that my "vbRetryCancel" is what's going on. I don't know if I need something to make the program loop back to the top to check for the file or what.

Basically I am taking records from the acadian.che file (but it has to be named acadian.txt) and then trying to delete the acadian.txt file so that it isn't used again. I was having a problem because the file wouldn't overwrite the acadian.txt file, so I put these if statements in to check if the files exist.

I am relatively new at this, so any help would be appreciated.


Public Function RenAcadianChe()

If Dir("c:\\imdata\acadian.che") = "" Then
MsgBox "The Health Insurance check inport file (acadian.che) does not exist. Please save the file to the \\GL_Server1\GLExpData share to continue.", vbRetryCancel
Else
If Dir(&quot;c:\\imdata\acadian.txt&quot;) <> &quot;&quot; Then
Kill &quot;c:\\imdata\acadian.txt&quot;
Name &quot;c:\\imdata\acadian.che&quot; As &quot;c:\imdata\acadian.txt&quot;
End If
End If

End Function
 
Instead of Name &quot;c:\\imdata\acadian.che&quot; have you tried this:

FileCopy &quot;c:\imdata\acadian.che&quot; &quot;c:\imdata\acadian.txt&quot;

Also, if you want to test which button the user pressed in a message box, use this syntax:

dim Response as Integer
Response = MsgBox(&quot;This is my prompt.&quot;,vbInformation Or vbRetryCancel)

If Response = vbRetry Then
'Retry code here
ElseIf Response = vbCancel Then
'Cancel code here
End if

Hope that helps!

-Mike Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top