Solved

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

Posted on 2011-02-27
3
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 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