How do I reference an older version of SAPI

I have developed a Microsoft Access program that uses a reference to Microsoft Speech Object Library. It allows me to add a little "fun" into an otherwise boring application.

I have developed the app on a Windows 7 PC that has Windows SAPI version 5.4 but when I try to run it on XP machines which runs an earlier version of SAPI, I get a missing or broken reference.

I want to distribute this as an MDE that will run with MS Access 2007 runtime and have it work on either Windows 7 or XP machines.

Does anyone know how I can distribute it with an earlier version SAPI? I know where to find the DLL on an XP Machine. Is it simply a case of distributing the earlier SAPI and registering it on the target machine or is that likely to mess things up badly?
Who is Participating?
Just googled for an example... see here...

It's hard to say without seeing the actual code.  But in general to avoid reference problems, you  can use 'Late Binding', which declares things as Objects rather than types specific to the libraries you are using.

For example. this is Early Binding, which will cause problems in a mixed version environment:

Dim objExcel as Excel.Application

To avoid reference problems between versions of Excel on different machines, you would replace that with Late Binding:

Dim objExcel as Object

That is the basic idea.  However some libraries have constants that would also have to be changed.  For example Excel has constants that can be used in code like xlBottom (or something like that) for the bottom border of a cell.  Using Late binding, constants like that need to be replaced with their actual value.  Chances are your code does not use any.  The quickest way to find out is to change the relevant declarations to Object and see if you code compiles.

As an aside, you lose vba's intellisense when you use late binding.  To make development easier, include declarations for both early and late binding.  When developing code, use early binding (Dim xlApp as Excel.Application), so that you can use intellisense/autocomplete as you are writing your code.  When your project is ready to release, comment that out and switch to "Dim xlApp as Object" to avoid reference issues.

That's generally how to do this - and might also help with the Speech Object Library (which I personally have never used).

You could try it out on a small 'test' database before applying it to your own db to see how it works.
Rob4077Author Commented:
Hi mbuzup,

Thanks for your explanation. The code it very straightforward but I can't seem to get it to work with late binding so I assume I am doing something wrong.
Here's the early binding code:

    Dim s As SpeechLib.SpVoice
    Set s = New SpeechLib.SpVoice
    s.Volume = 100
    s.speak Message
    Set s = Nothing

When I change to late binding (which I think should be as follows), I get the message "ActiveX component cant create object"

    Dim speaknow As Object
    Set speaknow = CreateObject("SpeechLib.SpVoice")
    speaknow.Volume = 100
    speaknow.speak Message
    Set speaknow = Nothing
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Have you definitely removed the SAPI reference from the references  list?
Rob4077Author Commented:
I hadn't but I have now and it still does the same thing.

I tried compiling on an XP machine then running on a Windows 7 machine and it works OK, but I don't want to do it that way unless I absolutely have to
Rob4077Author Commented:
Here's a sample dbf that works when I run it from Windows 7 but not from XP. How do I convert?
What I have seen before uses....

Set speaknow = CreateObject("SAPI.SpVoice")

but I don't have this library on my current machine so can't test anything.
Rob4077Author Commented:
Hi Peter,

that did the trick. Thanks for your help, yet again.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.