如何以编程方式将Access 1997 .mdb转换为Access 2007 .accdb [英] How to programmatically convert Access 1997 .mdb to Access 2007 .accdb

查看:244
本文介绍了如何以编程方式将Access 1997 .mdb转换为Access 2007 .accdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始构建一个应用程序,该应用程序从给定的根路径开始遍历文件夹结构,并将所有找到的Access 1997 .mdb文件转换为较新的Access 2007/2010 .accdb格式.但是,在进行实际文件转换时遇到了一些麻烦.

I'm in the starting process of building an application that walks through a folder structure, starting at a given root path, and converts all found Access 1997 .mdb files into the newer Access 2007/2010 .accdb format. However, I'm running into some troubles when doing to actual file conversion.

我正在使用Microsoft的Access Interop API( https://msdn .microsoft.com/en-us/library/office/ff193465.aspx )来处理转换,因此必须使用VBScript编写.脚本如下:

I'm using Microsoft's Access Interop API (https://msdn.microsoft.com/en-us/library/office/ff193465.aspx) to handle the conversion, so this has to be written in VBScript. Script is below:

Dim app 
Set app = CreateObject("Access.Application")
app.ConvertAccessProject "C:\Users\[User]\Access Conversion Utility\sample.mdb", "C:\Users\[User]\Access Conversion Utility\converted.accdb", acFileFormatAccess12

运行时,出现错误无法将项目转换为这种格式.只能将项目转换为Access 2000或更高版本."但是,无论文件参数枚举值是"acFileFormatAccess97"还是"acFileFormatAccess2000",都会显示相同的错误消息.有谁知道此错误的详细信息以及可能的解决方案?我尝试更改第二个参数的扩展名,认为这是问题的一部分,但这并未更改错误消息.

When run, I get the error "The project cannot be converted into this format. The project can only be converted to Access 2000 or newer format." Yet, this same error message shows up regardless of the file parameter enum value, be it 'acFileFormatAccess97' or 'acFileFormatAccess2000'. Does anyone know the details of this error and what a possible solution could be? I've tried changing the extension of the second parameter, thinking that was part of the issue, but this made no changes to the error message.

我正在使用的示例文件可以在Access中打开,只是转换本身失败了.

The sample file I'm using is able to be opened in Access just fine, it's just the conversion itself that fails.

总的来说,如果有人有更好的主意或方法以编程方式进行转换,我很想听听,但这是我唯一能找到的方法.计划是从用C#编写的GUI应用程序中运行此脚本,但也允许该应用程序也通过命令行运行.

By all means, if anyone has a better idea or approach to do the conversion programatically, I would love to hear it, but this is the only one I was able to find. The plan is to run this script from a GUI application written in C#, but also allow for the application to be run via the command line as well.

推荐答案

我正在使用Microsoft的Access Interop API ...因此必须使用VBScript编写.

I'm using Microsoft's Access Interop API ... so this has to be written in VBScript.

胡说八道.我只是在C#(Visual Studio 2010)中尝试过,在Access 2010中对我来说效果很好:

Nonsense. I just tried this in C# (Visual Studio 2010) and it worked fine for me with Access 2010:

// COM reference required for project
//     Microsoft Access 14.0 Object Library

var app = new Microsoft.Office.Interop.Access.Application();
app.ConvertAccessProject(
        @"C:\Users\Public\test\a97test.mdb",
        @"C:\Users\Public\test\a2007converted.accdb",
        Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2007);
app.Quit();

请注意,这几乎肯定会与Access 2013及更高版本一起使用,但对于那些版本的Access,COM Interop的VBScript实现也不会实现,因为它们绝对拒绝打开Access_97(及更早版本)数据库.

Note that this will almost certainly not work with Access 2013 and later, but neither would a VBScript implementation of COM Interop for those versions of Access since they absolutely refuse to open Access_97 (and earlier) databases.

这篇关于如何以编程方式将Access 1997 .mdb转换为Access 2007 .accdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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