ADO Library References and Forward Compatibility - vba

I'm looking to add some Access database functionality in a customer's Excel workbook app. Okay Excel & VBA aren't my first choice, but that is what we're working with.
Normally I use ADO through ADO.NET, so we always know the version because we've built for a specific version of .NET.
However with VBA and regular ADO, this is not the case.
Are the ADO libraries forward compatible? For example, if I referenced 6.0 would it work on everything from Vista onwards? (or 2.7 and XP)
Is there any way of doing this? Ie. referencing so that it will work on "all reasonably-installed versions". Or do I have to use late binding to ensure multi-version compatibility?
We need to support both 32 bit and 64 bit, so I'll be using ACE (and hence Access 2007 onwards). Waiting for confirmation on the XP - I suspect we can drop that too.

In my opinion you should use late binding in your situation. In such situation you can rely on compiler to use the most appropriate library available on computer where your code will be used.

Related

Repeatedly missing Microsoft Office references in Visual Basic

An Access database used by multiple people at my office occasionally flashes several error messages in quick succession and then loses some macro functionality. The first time it happened, I researched the topic and found a solution - there were missing references in Visual Basic that had to be fixed. Upon opening the reference list, 4 that were selected all read 'MISSING: Microsoft X 16.0 Object Library' where X is [Word, Powerpoint, Excel, Outlook]. I deselected these references, scrolled down and selected the 15.0 Object Library references. Things were back to normal, full macro functionality restored.
However, the references keep reverting back to 16.0 Object Library ones that are still missing. Sometimes it will be several weeks before I have to replace the missing references with the older version, sometimes it will happen the next day. It's not a difficult fix at all, but it keeps happening, and most of the other users would not know what to do.
I have to imagine the problem is persisting because the database is shared across multiple computers in the same office, though I believe all PCs have the same version of Microsoft Office installed. Any thoughts?
Despite what you believe, I suspect that someone has a newer version of Office, perhaps Access 2016 or an Office 365 subscription. I experience this problem at my office, but it is expected since I know that some computers have Access 2016 while I am using Office 2013.
Creating a separate front-end database is already a best practice for many reason. It would likely eliminate or reduce such problems with your shared database. The shared back-end database can be stripped of all code modules and macros that might be dependent on a particular version. The front-end can then be copied to each client. As long as the front-end database is distributed (i.e. copied) from a lesser version (i.e. references last set to Office 15.0 for example) to each client, any newer versions of Access will automatically update the references of only its local copy.
Yes this is a very annoying feature of Microsoft's Component Object Model. (Although it was extremely cutting edge when it was revealed to us in the mid 1990s.)
A practical solution is to switch the VBA to use late binding rather than early binding. In doing that you can drop the explicit reference altogether and the problem goes away.
A half way house is to use a late binding loader addin which, depending on the client configuration, loads an addin specific to their environment. That loaded addin can use early binding.
The second option might be more practical in that it would require fewer code changes.

What VB or VBA interpreters or compilers are available for the Windows operating system?

I am looking for an interpreter (compiler would work too) for Visual Basic or VBA. I am not looking for any kind of UI support. Basically, I have a series of somewhat complex VBA modules which make no reference to any external DLLs and make no use of any user interfaces. Is there any such tool available short of having Microsoft Office or Microsoft Visual Basic for the Windows operating system?
VBA only exists as an embedded "macro language" inside a host application like Excel. At one time you could even buy the SDK to embed VBA in your own applications, but there was never any "stand alone VBA."
VBScript is close to VBA and VB in syntax and semantics, but it also requires a host. Common desktop hosts include WSH, MSHTA, and the Vista/Win7 "gadget" framework. That's probably your best bet if it meets your needs.
It is remotely possible to do what you want using VB5CCE (Control Creation Edition) if you can find it. This was free, but could not compile to EXEs. It might have worked as an interpreter however by running it with the /run switch. I'm not certain of that though.
There are 3rd party freebies as well such as Jabaco which uses a very VB/VBA-like syntax.
Update: VB5CCE does not support the /run switch.
This might be worth a peek if VB.NET is a fit. Visual Studio Express ... I'm not sure what the free version leaves out though.
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express

How can I adapt a 32-bit VB6 application to work with 64-bit Office?

I have an application developed in VB 6.0 and VBA that uses latest Office 32 bit version. But since this application is 32 bit, it does not run on systems where 64 bit Office versions are installed. What is the best strategy I have to adopt to port this application to 64 bit. We have a mandate to use VB.NET and minimal (as much as possible) code modification from VB/VBA to .NET 64 bit. Please suggest the best option I can use so that I can leverage all best practices for this porting.
The answer of #Prof.Falken is fine, and porting to VB.NET may be a good idea for itself, but this does not guarantee that you get easily a 64 bit version of your application. If your .NET port will use 32 bit ActiveX components for which you have no 64 bit replacement, then this won't help. Here are some topics listed to be considered:
http://office.microsoft.com/en-us/word-help/choose-the-32-bit-or-64-bit-version-of-microsoft-office-HA010369476.aspx
In our workplace, systems administration decided not to install 64 bit Office on any of the new 64 bit Windows machines since here are too much applications in use (also from third party vendors) which would run into trouble else. And currently we don't see much benefits for us from the 64 bit Office version nowadays.
Here I found another link which might be interesting for you:
http://www.pcpro.co.uk/news/enterprise/356173/microsoft-warns-users-off-64-bit-office-2010
Depending on what the code looks like, one or both of these may be a good way:
a) Port it to VB.NET, or another language altogether.
b) Keep it in VB6, but replace EVERY place it talks to Office, with a wrapper call. This wrapper call talks to a VB.NET application, which in turn talks to Office.
The upshot of method b, is that it makes is possible to keep all the business logic in the old VB6 program untouched. Whether this is suitable or not depends on what the program looks like, what the programmers are experienced with, and so on. The old VB6 program and the new VB.NET could talk to each other through for instance COM or XML-RPC.

Will upgrading Office from 2003 to 2007 break VB programs which use Excel through the COM interop?

Assume all traces of Office 2003 will be removed from the computer.
UPDATE:
I understand that I will still be able to use .xls files. I'm asking about automating Excel through the COM interop from outside Excel. When I add a reference to Excel to a VB project, it gives me a different version of the dll for different versions of Excel. If a program was compiled with a reference to Office 2003's dll, will it need to be recompiled for Office 2007? Will the code need to be updated to use the new dll?
You should have no problem with your code breaking. In my past experiences, even though I referenced old versions of the Interop Assemblies, the newer version of Excel has been able to handle the calls.
Now the same can't be said for trying to use a newer version of the Interop Assemblies with an older version of Excel...
It would be very surprising if there were many breaking changes between the versions. As I understand it, Microsoft has a number of customers using Office, and they wouldn't like a large number of breaking changes.
In my opinion, the above is actually a valid way of analyzing many questions of this type: "Could x possibly happen" is aproximately equivalent to "what would happen to Microsoft if they did x". If the answer is "something really bad would happen", then chances are that Microsoft figured that out ahead of time.
Of course, this doesn't work 100%. "Could Microsoft ever remove Web Application Projects from Visual Studio 2005" is a counterexample.

VB.Net Automating MS Word for Spell Check Capabilities

An application currently in development has the requirements for using MS Word to perform spell check on certain textareas within the application.
I currently have Office 2007 (which is the Office 12 com objects).
My question is, if I add in the Office 12 objects what will happen on boxes which have Office 2003? This is in regards to both other development boxes as well as the end users.
Am I correct in believing that the end result will be that the spell capabilities will not be available for those users? And if I used an Office 11 object would that mean that the users would be unable to perform the spellchecks if they have Office 07 installed?
We gave up on trying to use a dependency on Word, as both have differing versions installed or no Office installation at all! Instead opting for NetSpell.
I am guessing here, but if it is as you can't use the 2007 PIA (Primary Interop Assembly) with a 2003 installation, you could try accessing the PIA via reflection as I would guess the calls you want won't change between the two, and then it won't matter - you'll use whichever is installed. If you are installing the PIA as well, you can then either get the user to tell you which they have, or be a little more clever and just try 2007 and if it fails, try 2003.
Like I said, I'm guessing here but it might be worth a try.
EDIT: I found this link about Office PIA's. This refers to Excel but actually covers Office in general. I don't envy the task you have. Looks like you'll need to detect the PIA (which may or may not be installed) and act accordingly. Sounds like a job for reflection to me.
Newer versions of Office will maintain most if not all compatibility with older versions of COM objects. Meaning if you want to program against Office 2003 and 2007 you will need to use Office 11 COM objects as a dependency as they were the newest available when 2003 was released. As long as you verify that the methods you need exist both versions of COM objects you should have no problems as long as you use the older COM objects.
Unfortunately, although I have used this solution for my own work, I have not tested it with Spell Check. In the end make sure that you test your code with all version of Office that you wish to integrate with.
My gut reaction to this question, is to simply suggest you go another route. Try using a 3rd party spell-check control. They are relatively inexpensive (and you may find some free controls). At least that way you can control the version of the control included with your app and be able to rely on it's functionality. Quite frankly, I'm surprised this library isn't built into Windows already. Sure it's complicated with all of the languages Windows supports, but these days it's similar to copy/paste in terms of user expectations.
You can actually package both the office11 and office12 interops needed to work in BOTH versions. It takes some minor work but I managed to do it. I do a check in the registry to see which interop to call and then executes the spell checking with the correct version. It even goes so far as to check if you have Word installed and throws an error alert that you can't spell check without having Word. We're tied to using Word due to the medical dictionary that's tied into Office we're required to use.
Do a search on interop or Com wrappers and I think you'll find you can use both fairly easily.