|
-
Nov 13th, 2009, 08:52 AM
#1
Thread Starter
Member
Back-up and restore using DAO,Acces as Database,vb6 application
Hello.. I need your expertise,
I am using the component DAO 3.6 in VB 6.0 and Access 2003 as Database, Can anyone know the code on how to back up and restore my data in my application?
-
Nov 13th, 2009, 08:54 AM
#2
Re: Back-up and restore using DAO,Acces as Database,vb6 application
Moved From The CodeBank (which is for posting finished code to be shared as opposed to asking questions)
-
Nov 13th, 2009, 09:48 AM
#3
Lively Member
Re: VB 6.0 Code for Back up and restore access database using DAO
The easiest way I have found is to simply copy the database file...
'Important...make sure the database workspace is closed!!!
DBEngine.Workspaces(0).Close
'copy the file
FileCopy DatabaseNameAndAddress, NewDatabaseNameAndAddress
You must also ensure that ALL recordsets opened by the app have been closed and set to nothing prior to closing the workspace.
I usually have a sub procedure something like this
Private Sub ReleaseAllRecordsets
Rs1.Close
Rs2.Close
Set Rs1 = Nothing
Set Rs2 = Nothing
etc
end sub
Obviously, if you have recordsets that have been declared as private you will need to release those recordsets within the form that they were declared. Thats why I generally declare all recordsets as public.
-
Nov 13th, 2009, 09:33 PM
#4
Thread Starter
Member
Re: Back-up and restore using DAO,Acces as Database,vb6 application
Thanks for your reply...FromDownUnder
Actually here is my code,I use common dialog 6.0 to save it in any folder
Code:
Private Sub Command1_Click()
Dim myDatabasePath As String
Dim strFileName As String
myDatabasePath = "D:\Information\Database.mdb" ' path of my original db file
With CommonDialog1
.Filter = "MS Access DB File | *.mdb"
.ShowSave
If Len(.FileName) > 0 Then
strFileName = .FileName
Else
Exit Sub
End If
End With
On Error GoTo Err
Dim Conn As New DAO.DBEngine
Dim strSource As String
Dim strDest As String
' Ensure file is not read only
SetAttr myDatabasePath, vbNormal
strSource = "DataSource=" & myDatabasePath & ""
strDest = "DataSource=" & strFileName & "dbengine(0)"
Conn.CompactDatabase strSource, strDest
Set Conn = Nothing
Exit Sub
Err:
Debug.Print Err.Description
End Sub
=>this code is only backing up database, but when I play this code, it is running but no database saved in the folder,..Please help
Last edited by si_the_geek; Nov 14th, 2009 at 05:34 AM.
Reason: added code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|