[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 934
  • Last Modified:

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?
0
Rob4077
Asked:
Rob4077
  • 4
  • 3
1 Solution
 
mbizupCommented:
Rob,

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.
0
 
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
0
 
peter57rCommented:
Have you definitely removed the SAPI reference from the references  list?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
0
 
Rob4077Author Commented:
Here's a sample dbf that works when I run it from Windows 7 but not from XP. How do I convert?
SayIt.mdb
0
 
peter57rCommented:
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.
0
 
peter57rCommented:
Just googled for an example... see here...

http://www.vbaexpress.com/kb/getarticle.php?kb_id=1036
0
 
Rob4077Author Commented:
Hi Peter,

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

Rob
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now