Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now