Copying a Database

ADO does not have a special method for copying files. However, you can set up a reference to the Microsoft Scripting Runtime reference in the Microsoft Visual Basic Editor screen to gain access to your computer file system, or use the CreateObject function to access this library without setting up a reference. The procedure in Hands-On 10-11 uses the CopyFile method of the FileSystemObject from the Microsoft Scripting Runtime Library to copy C:\NewAccessDb.mdb to the current folder on your computer. Recall that the C:\NewAccessDb.mdb file was created by the Create_NewDatabase procedure in Hands-On 10-10.

Part II

1. In the Visual Basic Editor window, choose Insert | Module.

2. In the module's Code window, type the Copy_AnyFile procedure shown below.

3. Choose Run | Run Sub/UserForm to execute the procedure.

Sub Copy_AnyFile() Dim fs As Object Dim strDb As String

Set fs = CreateObject("Scripting.FileSystemObject") strDb = "C:\NewAccessDb.mdb" fs.CopyFile strDb, CurrentProject.Path & "\" Set fs = Nothing End Sub

0 0

Post a comment