How do I create copies of CurrentDb using VBA

微笑、不失礼 提交于 2019-12-04 07:05:54

问题


I need to create copies of the CurrentDB using VBA (approx. 12 copies). The copies need to be clones of the master database containing all the same forms, queries, etc. except only a limited dataset.

DoCmd.CopyDatabaseFile seems to be made for this, but only works if you are using it to copy the DB to an MS SQL Server. As MS states on their website:

Copies the database connected to the current project to a Microsoft SQL Server database file for export.

docmd.TransferDatabase only exports the data itself, but not the structure, forms, etc.

Code I have found on the web and adapted doesn't work and throws an error on the .CopyFile line saying:

Run-time error 52: Bad file name or number

This is the code

Sub CopyDB()
Dim external_db As Object
Dim sDBsource As String
Dim sDBdest As String

sDBsource = "\\group\bsc\groups\L\BDTP\Compliance\ComplianceData\Compliance Group Reporting.accdb"
sDBdest = "\\group\bsc\groups\L\BDTP\Compliance\ComplianceData\Compliance Group Reporting_2.accdb"""

Set external_db = CreateObject("Scripting.FileSystemObject")
external_db.CopyFile sDBsource, sDBdest, True
Set external_db = Nothing

End Sub

How can I fix the above line? Alternatively is there a direct command in Access to create a copy? The "create backup" function would be tailor made for this, but I can not find it in VBA.


回答1:


Looks like you have an extra quote in sDBdest accdb""" And for database copy you can also use

FileCopy sDBsource, sDBdest

Instead of Scripting object



来源:https://stackoverflow.com/questions/39222351/how-do-i-create-copies-of-currentdb-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!