How to programmatically convert Access 1997 .mdb to Access 2007 .accdb - ms-access

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.
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
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.
The sample file I'm using is able to be opened in Access just fine, it's just the conversion itself that fails.
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.

I'm using Microsoft's Access Interop API ... so this has to be written in VBScript.
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();
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.

Problem is twofold.
First, Access 2007 and later won't read older formats than the JET 4 format of Access 2000.
Second, the constant for the 2007 format is acFileFormatAccess2007, not acFileFormatAccess12, it's the numeric value of the constant that is 12.
On this point, the documentation is wrong:
AcFileFormat Enumeration (Access)
So you will have to obtain an older version of Access for the first conversion to JET 4, then another step to convert to 2007 format.
Edit:
Or, of course, do as Gord shows.

Plain VBScript does not know about the ac* constants. So define them properly.

Related

ActCtx + manifest + comhost + .NET 6.0: does it work, does anyone has a working example?

My goal is to expose a .NET 6.0 library to COM, in order to use it from VBA in MS Access. And to use the manifest approach rather than using the registry.
Got article "Exposing .NET Core components to COM" working, using their "COM server sample" example code.
This example however requires that a manifest file is present in the folder containing the executable. When using the COM object from MS Access we do not want to place the manifest file and other files in the MS installation folders.
The suggested solution is to create an Microsoft.Windows.ActCtx object and let that object create my COM object, using the Manifest property of the ActCtx object to specify the manifest file.
This is the part that continues to fail. actCtx.CreateObject("") gives an Invalid Cast exception, even without assignment of the result to a variable, hence it is an internal issue. No additional details, no information in the event log. Tried this in C# and from VBA.
I have a few questions:
Is ActCtx the way to specify the manifest path, or is there a better way to do this from VBA in MS Office?
The example uses a COM host, which seems to be some COM class / object factory, which in turn helps creating my COM object. As opposed to .NET Framework this COM host seems to be introduced for .NET Core; .NET 6.0 in my case. Is the COM host required? Is the simpler direct instantiation possible?
Does anyone has answers to these questions, tips, or even better: a working example?
Some progress but I am still not happy. Abandoned the ActCtx approach for a while and tried to create the COM server object of the sample directly in MS Access VBA. Added a reference to the com host, say COMServer.comhost.dll, as opposed to the implementation COMServer.dll. Created the object, simply with New. Error: class not registered. Performed a regsvr32 COMServer.comhost.dll and the sample works.
Although the sample works there are now again registry entries: the guid of the server class has been added to the registry. Regfree COM not achieved.
This is despite COMServer.comhost.dll looking promising. A tlb type library built separately and embedded in the .dll is seen by VBA: intellisense works and the object browser works. The manifest seems to be correctly embedded in the .dll too, and takes precedence over the manifest on disk.
The question remains how to avoid the regsvr32 step and make the solution working by just adding the reference to COMServer.comhost.dll, in MS Access VBA.

Searching for referenced file Excel.exe in VBA script after converting to Office 2013

I have an Access application that I share with other users. We share the database on a Sharepoint site and each check it out / download it for edits, then put it back in Sharepoint and check it back in. We do it this way because response time if we all share the same copy on a server is unacceptable, and we only need one person to have acces at any one time. That's not my problem right now.
Last week, my old PC died and I replaced it with a new one. The old PC is Windows7, 32 bit, with Office 2010. The new PC is also Windows7, but 64 bit and with Office 2013. As far as I know, I did not change the database format to a new version of Access or make any other changes. The data base still works fine on my new PC.
The VBA script integrates the data base with Excel workbooks and exports data to Excel. One reference I have selected is Microsoft Excel 15.0 Object Library - the same reference I've always used. Now, when I load the database back to the server and other users downloads it, they can open the data base but get an error that says "Searching for reference file Excel.exe", followed by “Undefined function ‘Format’ in expression”.
The other users' PCs are configured the way my old one was, and they were able to use the database with no problems before I converted to Office 13 and saved my copy back to the server.
So my questions are - what is causing this, and more importantly, what can I do to fix it?
"... reference I have selected is Microsoft Excel 15.0 Object Library ..."
That Microsoft Excel 15.0 Object Library is the version for Office 2013. With Office 2010, the version is Microsoft Excel 14.0 Object Library.
The reference was originally 14.0 when you developed and used the db in Access 2010. When opened in Access 2013, Access adjusted the reference to its available version (15.0). Unfortunately, when you try to use the db again in Access 2010, Microsoft Excel 15.0 Object Library is meaningless to that Access version, so it doesn't know to use Microsoft Excel 14.0 Object Library instead.
The fix is to remove that reference and convert your code to use late binding.
Here is a brief example of late binding, copied from Using early binding and late binding in Automation:
' Declare the object as a late-bound object
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
Note, if your code uses Excel named constants, you will need to substitute the constants' values for their names, or declare the constants in your code.

Access 2013 file to open in Access 2007

I made Access Form which was working fine in Access 2013 and Access 2007 until I add some new features(I don't remember what) to it.
After adding them, it keeps giving me error "Unrecognize file format" when I try to run it in Access 2007. Meanwhile it runs fine in Access 2013.
I want to ask if there exists some software to convert Access 2013 file to Access 2007? Or is there any way make it compatible to 2003? When I Save As 2003 file it don't because of some added features.
Please help!
You could try using Access' Application.SaveAsText in 2013 and Application.LoadFromText in 2003.
Even if this doesn't work directly, if you have an older version that does work, you could compare the differences between the text files the two versions of Access produce, as SaveAsText produces (for the most part) human readable output; the only unreadable parts are typically images.
I've had this happen to me during development on A2010 and deployment on A2007. The possibilities are explained on this page. It is likely that you added an Empty Cell control to a form that had a VBA module (or added a module to a form with an Empty Cell control). I did this unknowingly by inserting a row into the AutoHeader that is created in forms by the Form Wizard.
Follow the steps at the bottom row of Table 2 to rectify this.

Convert Access 2010 accdb to 2007 accdb

I'm trying to convert an accdb file from use in Access 2010 to Access 2007. I first tried opening the file with Access 2007 and I get the error Unrecognized database format. I was able to get my backend to open in 2007 by removing the MSysResources table (which uses the new attachment datatype) but the same technique has not worked with my front end.
My front end does use a webbrowser control (which Microsoft claims won't work but also won't stop the file form being opened). I thought I'd better import one form at a time to see where the error is. While in a new, blank 2007 file I tried to use External Data>Access to import one form (a very simple form, a button, two text boxes). Same error as opening the whole file. I tried having 2010 open at the same time as 2007 and copy/pasting the form over. Same error. Unrecognized database format.
I then try to export the form using Application.SaveAsText in 2010 and import using Application.LoadFromText in 2007. There were errors importing but at least this method generates an error log. The error.txt file has issue with the header line PublishOption =1. After I remove that I continually get errors regarding theme settings. I remove every line it has a problem with which are from there on all theme related (HoverForeThemeColorIndex, AlternateBackThemeColorIndex...). I never did get rid of enough of these to successfully import the form though.
Where am I going wrong? If, like I suspect, I cannot use a theme generated in 2010 in 2007, how can I remove all these references from all my forms? Is this actually the problem? How can I more smoothly move back to a 2007 file?
Edit: It turns out the client is on Office 2007 SP2. I'm going to update my development machine and try all this again. I was not using nay service packs originally.
According to the Microsoft support article
Backward compatibility between Access 2010 and Access 2007
an Access 2010 database can be reverted back to "Access 2007 format" by
removing all Access_2010-specific features from the database (details in the article),
creating a new "Blank Database" (not "Blank Web Database"), and
using External Data > Import in Access 2010 to import all objects (tables, forms, etc.) from the previous database into the new (empty) one.
The list of features that must be removed include a couple that may not be immediately obvious to a casual inspection of the original Access 2010 database, such as
using a new or updated database sort order, and
using "Access 2010 encryption compliance".

Import MS Word Form Field to Access - Missing Reference?

I am trying to import data into access 2007 from a MS Word form field.
I have followed the tutorial here: http://msdn.microsoft.com/en-us/library/aa155434(v=office.10).aspx
When I run the VBA code I get a compile error that says "User-defined type not defined". After doing some research I've found that it is likely because I am missing a reference to an object in an object library.
I have the following object libraries referenced:
Visual Basic For Applications
Microsoft Access 12.0 Object Library
Ole Automation
Microsoft Office 12.0 database engine Object library
Microsoft Word 12.0 Object library
The error is thrown when the sub is called here:
Sub GetWordData()
Am I missing a reference, or do I have another problem?
Thanks in advance
Ensure that you have set a reference to the Microsoft ActiveX Data Objects x.x Library.
In the code window, choose Tools->References, scroll to the library and tick it.
Note that using library references, rather than late binding (Create.Object("Word.Application")), makes it easier to access properties and methods but can mean that your code will not run in other environments.