Solved

VB6 Access Copy database

Posted on 2010-08-13
4
322 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auto Filter in Combo Box 7 32
SQL profiler equivalent in MS-Access 3 42
vbModal 12 34
Dropdown Not In List - not working correctly 11 37
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

23 Experts available now in Live!

Get 1:1 Help Now