How to programmatically backup Access database using VB6?

B

Brian

I've searched the net for an example of how to programmatically backup an
Access database using Visual Basic 6, but have found little of value as the
few available examples simply copy the database. I believe there's a better
way of doing this using an instance of the Access object which verifies the
data - something like the 'compress and repair' option available under the
Tools menu, but don't know enough to do this.

How should this be done programmatically? VB6 code-snippet greatly
appreciated!

Brian
 
L

Larry Linson

comp.databases.ms-access isn't a particularly good place to get VB6 code
snippets, because most of the people here will tell you that there's rarely
good reason to use a VB6 front end with an Access/Jet database, in "normal
business applications". I've used classic VB since version 1, but never for
database applications, because it is so much easier to do in Access the
database work I wanted to do.

You might search the archives of this newsgroup at http://groups.google.com,
using Advanced Group Search, or you might seek a newsgroup that deals with
general VB questions, like comp.lang.basic.visual.misc if you didn't get
response from your posting to comp.lang.basic.visual.database, or one of the
microsoft.public.vb.database newsgroups -- there's that base group, then
append .ado, .dao, .odbc, .rdo for specifics on which access method you're
using.

Are you certain that Access will be installed on the target machine? It
often is not, and certainly need not be for VB to access a Jet (often, yes,
even by Microsoft, called an Access) database. Jet 3.51 came with the
original release of VB6, and was updated to Jet 4.0 with one of the Service
Packs to VB6.

Larry Linson
Microsoft Access MVP
 
L

Larry Kaplan

Brian said:
I've searched the net for an example of how to programmatically backup an
Access database using Visual Basic 6, but have found little of value as the
few available examples simply copy the database. I believe there's a better
way of doing this using an instance of the Access object which verifies the
data - something like the 'compress and repair' option available under the
Tools menu, but don't know enough to do this.

How should this be done programmatically? VB6 code-snippet greatly
appreciated!

Brian

http://www.mvps.org/access/

HTH
Larry Kaplan MVP

This posting is provided "AS IS" with
no warranties, and confers no rights.
 
P

Phil Stanton

If it's any help I could email you a small bit of a database which allows
you to back up either to Floppy (Zipped file) or to CD. If you would like
this, please e-mail me direct with the subject Access backup.

Phil
 
M

Mike

I used this stuff to backup my database before it loads.....

hope it works..

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


Sub backup()
Dim SourceFile, DestinationFile, tryagain, result
Dim strBackupEXT As String
MousePointer = vbHourglass

strBackupEXT = Format(Format(Date, "ddmmyy"), "000000")
'Backup Database
On Error GoTo handler
SourceFile = Path & WarrantyDB ' Define source file name.
DestinationFile = PathBak & "Warranty_" & strBackupEXT & ".mdb" '
Define target file name.
result = apiCopyFile(SourceFile, DestinationFile, False)
If result = 0 Then
Do Until result = 1
tryagain = MsgBox("Back-up failed....", vbRetryCancel)
If tryagain = vbRetry Then
result = apiCopyFile(SourceFile, DestinationFile, False)
If result = 1 Then
MsgBox "Back-up complete !!"
MousePointer = vbNormal
End If
Else
MsgBox ("WARNING - NO BACK-UP DONE !!!!")
result = 1
MousePointer = vbNormal
End If
Loop
Else
' MsgBox "Back-up complete !!"
MousePointer = vbNormal
End If

Err.Clear

Exit Sub

handler:
Select Case Err.Number
Case 70
MsgBox "Error No. > " & Err.Number & " / " & Err.Description
Resume Next
Case 75
Resume Next
Case Else
MsgBox "Error No. > " & Err.Number & " / " & Err.Description
End Select

End Sub
 
L

Larry Linson

Larry Kaplan = Don P Mellon, who isn't a Microsoft MVP. Don is the only one
in all the newsgroups where I participate who seems to think that a bare
base URL is a useful answer. As far as I know, the site which he references
does not have any information on backing up Jet from VB6, but it does have
plenty of good information about Access and Jet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top