Solved

VB6 Access Copy database

Posted on 2010-08-13
4
320 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 84
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 119

Accepted Solution

by:
Rey Obrero earned 500 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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