如何使用VBA创建CurrentDb的副本 [英] How do I create copies of CurrentDb using VBA

查看:135
本文介绍了如何使用VBA创建CurrentDb的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用VBA创建CurrentDB的副本(大约12个副本).副本必须是主数据库的克隆,其中除了有限的数据集外,还包含所有相同的形式,查询等.

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似乎是为此而创建的,但是仅当您使用它将DB复制到MS SQL Server时才起作用.如MS在其网站上所述:

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:

将连接到当前项目的数据库复制到Microsoft 用于导出的SQL Server数据库文件.

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

docmd.TransferDatabase仅导出数据本身,而不导出结构,表单等.

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

我在网络上找到并改编的代码不起作用,并在.CopyFile行上引发错误,提示:

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

运行时错误52:文件名或数字错误

Run-time error 52: Bad file name or number

这是代码

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

如何解决以上问题?另外,Access中是否有直接命令来创建副本?为此,将量身定制"创建备份"功能,但是我在VBA中找不到它.

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.

推荐答案

看起来您在sDBdest accdb"""中有一个额外的引用 对于数据库复制,您还可以使用

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

FileCopy sDBsource, sDBdest

代替脚本对象

这篇关于如何使用VBA创建CurrentDb的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆