• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

How create a copy of the current database and give it a name

From a command button of a form I want to create a backup copy of the current database and be able to give it a name.

How can this be done?

--Steve
0
SteveL13
Asked:
SteveL13
  • 7
  • 6
1 Solution
 
GozrehCommented:
FileCopy "YourCurrentDB.mdb","YourNewFile.mdb"

But you can only do it on other database, not on that is now active
0
 
SteveL13Author Commented:
But won't that give the new file a static name of YourNewFile.mdb ?

I want them to be able to name it as it is being copied.
0
 
GozrehCommented:
   Dim Result As String
   Result = InputBox("Please Enter Name Of New File")
   FileCopy "YourCurrentDB.mdb", Path & "\" & Result & ".mdb"

Open in new window

0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
SteveL13Author Commented:
Am getting an error.  Says it can't find the file.

Here is what I have...

   FileCopy "myfilename.accdb", Path & "\" & Result & ".accdb"

Note the accdb extension.
0
 
GozrehCommented:
you need to put in full path
0
 
SteveL13Author Commented:
What would the code be for a user that may have it in their own Document folder?

I don't want it to be a static address but use the current user's Documents folder.
0
 
GozrehCommented:
If the file that you want to copy is in same location that you current application you can use CurrentProject.Path

If you want to use the user My Documents, you can use = Environ$("USERPROFILE") & "\My Documents\"
0
 
SteveL13Author Commented:
So then is this it?

FileCopy "myfilename.accdb", CurrentProject.Path & "\" & Result & ".accdb"
0
 
GozrehCommented:
FileCopy CurrentProject.Path & "\myfilename.accdb", CurrentProject.Path & "\" & Result & ".accdb"
0
 
SteveL13Author Commented:
Now am getting a permission denied message.
0
 
GozrehCommented:
I wrote before
But you can only do it on other database, not on that is now active
it will only work if you want to copy the backend database, or another database
you canot copy file that is currently open
0
 
GozrehCommented:
was this the solution what you nedded, or you want to copy the actual file you are currently using ?
0
 
SteveL13Author Commented:
This solution is working fine.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now