Solved

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

Posted on 2011-02-27
3
348 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 500 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

831 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