?
Solved

VB6 Access Copy database

Posted on 2010-08-13
4
Medium Priority
?
351 Views
Last Modified: 2012-05-10
Hey,

Im adding a backup feature to my program, and am needing to copy my database to a specified location.
Problem is im unable to close the database so im needing to know how to re-create the database at the specified location.

Any ideas?

Thanks!
0
Comment
Question by:Letsgetcoding
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33427899
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21364411.html?sfQueryTermInfo=1+10+30+access+backup+dhaest

Easiest way to backup a access-database: Just copy the file to another location
(in vb:    
dim strFileNameOriginal as string
dim strFileNameBackup as string
strFileNameOriginal = "c:\YourPath\YourDatabase.mdb"
strFileNameBackup = "c:\Backup\YourDatabase.mdb"

FileCopy strFileNameOriginal, strFileNameBackup

Otherwise, you can take a look at:
With the help of this tool you can take backup of your MS-Access files and also restore the files.
With Auto backup facility and more. Try it.
http://www.a1vbcode.com/download.asp?ID=3252
0
 
LVL 85
ID: 33428583
Also remember that it is NEVER a good idea to copy an in-use Access file (or any other file for that matter). In most cases it won't matter, but if you happen to copy that file at the same time as someone attempts to write to the database, you'll end up with a corrupt file - and the only thing worse than no backup is a corrupt backup :)

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 33428700
place this codes in a regular module

Option Compare Database
Option Explicit

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Function fnc_CopyFile(ByVal sFromFile As String, ByVal sToFile As String) As Boolean

    Dim lRv As Long
   
   
    On Error Resume Next
   
    DoCmd.Hourglass True
    lRv = CopyFile(sFromFile, sToFile, True)
    If lRv = 0 Then
        MsgBox "File Copy failed.", vbCritical, "File Copy"
        fnc_CopyFile = False
    Else
        fnc_CopyFile = True
    End If
    DoCmd.Hourglass False
End Function

'pass the values to the function
0
 

Author Comment

by:Letsgetcoding
ID: 33433118
Hey,

Yeah I have use FileCopy before but it didnt work out as if the Database was open which in most cases it is, I would get a permission denied error.

Will give these methods a go now.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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.
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…
Suggested Courses

862 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