Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If file already exists ask user to save as a different file

Posted on 2011-02-27
3
Medium Priority
?
354 Views
Last Modified: 2012-06-27
Experts,

Currently I am using the following code to check and see if a file with the same name exists. If so, delete the file and replace with a new file.

What I would like to do is check to see if the file exists, if so, then generate a message that says something like, "file already exists, would you like to save it with a different file name?" If the user says 'yes' then I would like to generate a 'save as' dialogue box OR a input box to alow the user to save the file name differently.

How would I code this?

Thanks!
If Dir(TheFile) <> "" Then
   Kill (TheFile)
 Else
    TheFile = CurrentProject.Path & "\TripReport-" & strPlace & "-" & strUserName & "-" & TheDate & ".rtf"
 End If
 
    DoCmd.OutputTo acReport, "rptTrip", "RichTextFormat(*.rtf)", TheFile, , , acExportQualityScreen

Open in new window

0
Comment
Question by:shogun5
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 2000 total points
ID: 34994406
Try this ...

 TheFile = CurrentProject.Path & "\TripReport-" & strPlace & "-" & strUserName & "-" & TheDate & ".rtf"
 End If

If Dir(TheFile) <> "" Then
    If MsgBox("File already exist, save with a different name?", vbYesNo, "") = vbYes Then
          ThFile = InputBox("Enter a path and file name.")
    End If  
End If
 
DoCmd.OutputTo acReport, "rptTrip", "RichTextFormat(*.rtf)", TheFile, , , acExportQualityScreen


ET





0
 

Author Closing Comment

by:shogun5
ID: 34996156
Okay, this got me to the final solution:

TheFile = CurrentProject.Path & "\TripReport-" & strPlace & "-" & strUserName & "-" & TheDate & ".rtf"
 
         If Dir(TheFile) <> "" Then
            If MsgBox("File already exist, save with a different name?", vbYesNo, "") = vbYes Then
                  TheFile = InputBox("Enter a path and file name.", "File Name", TheFile)
            End If
        End If

Thank!
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 34998996
Thanks for the points.

ET
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question