473,322 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Backing up an Access mdb file - how best to automate?

MLH
I'm developing an app that I'd like to backup each time I open it for
modifications. Is it too late to do so after opening the file with
Access? Here's what I've been trying... Trevor Best posted
this code in 1995...

On frmMainMenu, I have a Fn that I launch with a button. Here
is the function:

Sub CopySingleFile (szSrc As String, szTgt As String)

Const BYTE_SIZE = 20480
Dim hfInput As Integer
Dim hfOutput As Integer
Dim lFilePointer As Long
Dim lRemain As Long, lFileLen As Long
Dim szBuffer As String
On Error GoTo CopySingleFileError

hfInput = FreeFile
Open szSrc For Binary Access Read Shared As #hfInput
hfOutput = FreeFile
Open szTgt For Binary Access Read Write Lock Read Write As
#hfOutput
'Open file [For mode] [Access access] [lock] As [#]filenumber [Len
= reclen]
lRemain = LOF(hfInput)
lFileLen = lRemain

lFilePointer = 1
Do Until lRemain < BYTE_SIZE
szBuffer = Input(BYTE_SIZE, #hfInput)
Put #hfOutput, lFilePointer, szBuffer
lRemain = lRemain - BYTE_SIZE
lFilePointer = lFilePointer + BYTE_SIZE
lBytesCopied = lBytesCopied + BYTE_SIZE
Loop
szBuffer = Input(lRemain, #hfInput)
Put #hfOutput, lFilePointer, szBuffer
lFilePointer = lFilePointer + lRemain

CopySingleFileExit:
On Error Resume Next
Close #hfInput
Close #hfOutput
Exit Sub
CopySingleFileError:
Select Case MsgBox(Error$(Err), 48 + 2, "Error " & Err)
Case 3
Error Err
Case 4
Resume
Case 5
Resume CopySingleFileExit
End Select
End Sub
I have a button on the main menu that runs

Call CopySingleFile("c:\cr\MyFile.mdb", "c:\MyBak.mdb")

when I click it. However, I get an error #70
(permission denied) when I click the button.
Is something wrong with my logic? Should I
be using CopyObject to recreate the database
and all its objects instead?

Thx
Nov 12 '05 #1
3 6415
I back up my production database four or five times a day. First I close it
and it runs the compact thingy on close. I then have this $20.00 program
called ZipFiler that I have setup to backup to a local drive and to backup
to a network drive. Usually takes about 15 seconds to backup to each
location. As far as I know there isn't a method to backup an Access database
either on opening or closing. Though on second thought you could probably
run a batch file that zips it up before opening.

I recommend you check out the Zipfiler program (I have shares (:<) ).
http://www.zipfiler.com/

"MLH" <CR**@NorthState.net> wrote in message
news:lk********************************@4ax.com...
I'm developing an app that I'd like to backup each time I open it for
modifications. Is it too late to do so after opening the file with
Access? Here's what I've been trying... Trevor Best posted
this code in 1995...

On frmMainMenu, I have a Fn that I launch with a button. Here
is the function:

Sub CopySingleFile (szSrc As String, szTgt As String)

Const BYTE_SIZE = 20480
Dim hfInput As Integer
Dim hfOutput As Integer
Dim lFilePointer As Long
Dim lRemain As Long, lFileLen As Long
Dim szBuffer As String
On Error GoTo CopySingleFileError

hfInput = FreeFile
Open szSrc For Binary Access Read Shared As #hfInput
hfOutput = FreeFile
Open szTgt For Binary Access Read Write Lock Read Write As
#hfOutput
'Open file [For mode] [Access access] [lock] As [#]filenumber [Len
= reclen]
lRemain = LOF(hfInput)
lFileLen = lRemain

lFilePointer = 1
Do Until lRemain < BYTE_SIZE
szBuffer = Input(BYTE_SIZE, #hfInput)
Put #hfOutput, lFilePointer, szBuffer
lRemain = lRemain - BYTE_SIZE
lFilePointer = lFilePointer + BYTE_SIZE
lBytesCopied = lBytesCopied + BYTE_SIZE
Loop
szBuffer = Input(lRemain, #hfInput)
Put #hfOutput, lFilePointer, szBuffer
lFilePointer = lFilePointer + lRemain

CopySingleFileExit:
On Error Resume Next
Close #hfInput
Close #hfOutput
Exit Sub
CopySingleFileError:
Select Case MsgBox(Error$(Err), 48 + 2, "Error " & Err)
Case 3
Error Err
Case 4
Resume
Case 5
Resume CopySingleFileExit
End Select
End Sub
I have a button on the main menu that runs

Call CopySingleFile("c:\cr\MyFile.mdb", "c:\MyBak.mdb")

when I click it. However, I get an error #70
(permission denied) when I click the button.
Is something wrong with my logic? Should I
be using CopyObject to recreate the database
and all its objects instead?

Thx

---
This email from Barry Wright has been scanned using AVG 6.0 and is certified
Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.541 / Virus Database: 335 - Release Date: 11/15/03
Nov 12 '05 #2
On Sun, 16 Nov 2003 14:34:07 -0500, MLH <CR**@NorthState.net> wrote:
I'm developing an app that I'd like to backup each time I open it for
modifications. Is it too late to do so after opening the file with
Access? Here's what I've been trying... Trevor Best posted
this code in 1995...


One option you might take a look at is to SaveAsText all of the
objects when you open the db. Although if you open a lot you are going
to have a *lot* of backups; those will have to be managed somehow.
Application.

SaveAsText is an undocumented function that will save your objects as
text. To get information about the arguments for it open the object
browser and right click on it somewhere and select "Show Hidden
Members" then you can run it from the debug window.

Application.SaveAsText

Another function LoadFromText will restore the objects.

Lyle Fairfield has posted code about backups using this approach,
although I believe it was for an ADP. It should be no problem to
convert to MDB. Search Google groups for that.

- Jim
Nov 12 '05 #3
MLH
Thx, guys, for the suggestions. I took the easy way out...
Anytime I start my production database, the following code
runs...

On Error Resume Next
DoCmd Hourglass True
Dim I%, Tmp, MyDb As Database

Kill "MyDB.bak"
Set MyDb = DBEngine(0).CreateDatabase("MyDB.bak", DB_LANG_GENERAL)
Set MyDb = DBEngine(0)(0)
For I = 0 To MyDb.TableDefs.count - 1
Tmp = MyDb.TableDefs(I).name
If Mid(Tmp, 2, 3) <> "Sys" Then DoCmd CopyObject "MyDB.bak", Tmp,
A_TABLE, Tmp
Next I
For I = 0 To MyDb.QueryDefs.count - 1
Tmp = MyDb.QueryDefs(I).name
DoCmd CopyObject "MyDB.bak", Tmp, A_QUERY, Tmp
Next I
For I = 0 To MyDb.containers("Forms").documents.count - 1
Tmp = MyDb.containers("Forms").documents(I).name
DoCmd CopyObject "MyDB.bak", Tmp, A_FORM, Tmp
Next I
For I = 0 To MyDb.containers("Reports").documents.count - 1
DoCmd CopyObject "MyDB.bak", Tmp, A_REPORT, Tmp
Tmp = MyDb.containers("Reports").documents(I).name
Next I
For I = 0 To MyDb.containers("Scripts").documents.count - 1
Tmp = MyDb.containers("Scripts").documents(I).name
DoCmd CopyObject "MyDB.bak", Tmp, A_MACRO, Tmp
Next I
For I = 0 To MyDb.containers("Modules").documents.count - 1
Tmp = MyDb.containers("Modules").documents(I).name
DoCmd CopyObject "MyDB.bak", Tmp, A_MODULE, Tmp
Next I
DoCmd Hourglass False: Beep

The code runs when I launch the app. So if, during a braindead
moment, I inadvertently blow away an important object or trash
something that I worked on all day yesterday, I can take comfort
in knowing that I have a .BAK copy of the app as it was immediately
before starting my mods to it this morning. Works for me.
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: goermezer | last post by:
Hello, I have some problems to automate a CAD (computer aided design) Software called CATIA V5 from Dassault Systemes. CATIA V5 has a builtin VB-Editor like Word, Excel, … and registers itself...
1
by: Hlpl | last post by:
Hi I have a VB.net windows application that uses an MSDE database I need to give the user the option to backup this data (and later restore it). Ideally I want to back the data up to an empty...
10
by: MLH | last post by:
I print to a device that creates a PDF. Knowing the filename, how can I then embed the PDF into the body text of an OutLook Express outbound email & send to a specified address in a table? I want...
7
by: Mike Dwyer | last post by:
I need a VB 6 app to automate a microsoft access MDB application. Specifically, it needs to open a form in Access and read information keyed into that form. I know this is "old school" but I'm...
1
by: Pavs | last post by:
This may not be the place to ask however i am looking for resources on how i may document data I am backing up from an oracle database to MS Access. Basically I have my oracle database and i...
4
by: bborden | last post by:
I am considering writing a database program that contains text and images with an easy to use interface for my friend's dermatology physician practice. Basically Patient information that links to...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
0
by: rcoutts | last post by:
I have a custom Access database that is a bulk mailing program for my small business to send emails to my customers (not spam!). Before sending mail, I export a folder in Outlook to an Access MDB...
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.