Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you duplicate a database from Visual basic code? 1

Status
Not open for further replies.

Arnold

Programmer
Jul 2, 1999
32
0
0
NL
Visit site
While in visual basic code, I want to do the equivalent of copying another database and pasting it with a different name. I don't want to make a replica of it. I do know that I could create a new database with the NewCurrentDatabase Object and then import everything that I want, but I was looking for a way to do it with "RunCommand" or "DoCmd". I did try the "Application.RunCommand acCmdSaveAs" code, but it was trying to do a SaveAs for the form, and not an outside database. The database I am trying to make a copy of is not the one I have open, it is a different one. Any ideas?
 
You could try copying the actual file using the CopyFile function provided with the Windows API.<br>
<br>
Add the following line to the declare section of a module:<br>
<br>
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long<br>
<br>
Then you can call it as follows:<br>
<br>
Dim lngReturn as Long<br>
<br>
lngReturn = CopyFile(strExistingName, strNewName, True)<br>
<br>
The last argument is True if you want it to fail if a file called strNewName already exists.<br>
<br>
The return value is nonzero if the action is successful and 0 if it fails.<br>
<br>
I don't know if this is the best way to do it, but it would work. (probably!)<br>
<br>
Jonathan
 
Thanks Jonathan, that helped out a ton! It worked great.<br>
<br>
Arnold<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top