By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,506 Members | 2,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,506 IT Pros & Developers. It's quick & easy.

Exporting data - Check to see if file exists

P: 47
Hello Everyone,

I would like to export data from a form in access to a static location on the user's hard drive with the same name everytime. The problem with this is that when you use the transfertext function in vbscript it does not ask if you would like to overwrite the old file it just does.

Is there a way to check if a file already exists before exporting and overwriting? If so how? I would like the user to see a messagebox asking if they want to overwrite or cancel.

Thanks!
Jul 24 '07 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,316
Here's a code snippet of what I use for that very purpose.

Expand|Select|Wrap|Line Numbers
  1.         If Dir(path) <> "" Then
  2.             If MsgBox(path & " already exists." & Chr(13) & "Do you wish to overwrite the file?", vbYesNo) = vbYes Then
  3.                 Kill path
  4.             Else
  5.                 Exit Sub
  6.             End If
  7.         End If
  8.  
Jul 24 '07 #2

FishVal
Expert 2.5K+
P: 2,653
Hello Everyone,

I would like to export data from a form in access to a static location on the user's hard drive with the same name everytime. The problem with this is that when you use the transfertext function in vbscript it does not ask if you would like to overwrite the old file it just does.

Is there a way to check if a file already exists before exporting and overwriting? If so how? I would like the user to see a messagebox asking if they want to overwrite or cancel.

Thanks!
Hi!

This maybe some simple function like the following one.
Expand|Select|Wrap|Line Numbers
  1. Public Function DoesFileExist(strPath As String) As Boolean
  2.  
  3.     On Error GoTo Failed
  4.  
  5.     FileLen strPath
  6.     DoesFileExist = True
  7.     Exit Function
  8.  
  9. Failed:
  10.     DoesFileExist = False
  11.  
  12. End Function
  13.  
Jul 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.