Thanks for the info guys that got me up and running nicely.
However, I'd still like to know for my own reference how to programmatically
see what COM references the user has available and add/remove them
programmatically.
Take this example for instance, my boss has Microsoft Speech SDK 5.1
instaleld, but the person opening doesn't. I can look at the References
object to see if they have it loaded and use Late Binding to create the
object. However, of course as you know if you have even one Missing ref then
nothing will work at all, and if I programmatically remove it for her, then I
have to readd it for me or for my boss.
So what I would like to know is how to programmatically pull a listing of
what COM refs are available for a particular system which I'm more than
likely sure has to be done through the Win32 API. That way I can see if a
user has the ref available and programmatically add it (then remove it at the
end of execution).
> Consider using Late Binding instead. Tony Toews has an introduction to the
> topic at http://www.granite.ab.ca/access/latebinding.htm
[quoted text clipped - 36 lines]
> > few
> > others.
> Thanks for the info guys that got me up and running nicely.
>
[quoted text clipped - 15 lines]
> way I can see if a user has the ref available and programmatically
> add it (then remove it at the end of execution).
I don't understand. If you use late binding then you don't need the
reference.

Signature
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
BlockNinja - 27 Sep 2006 17:26 GMT
Ah so you don't need references *AT ALL* if you are doing Late Binding then?
i.e. If I want to CreateObject a Microsoft.Speech object, the user doesn't
need to still have the Microsoft Speech Object Library reference checked? I
also want to be able to trap errors too though if I try to create the object
and it doesn't exist.
> > Thanks for the info guys that got me up and running nicely.
> >
[quoted text clipped - 18 lines]
> I don't understand. If you use late binding then you don't need the
> reference.
Using Late Binding is infinitely preferable. You won't run into versioning
problems.
With Late Binding, you don't need the reference at all. In the case of the
Speech SDK, your code is probably something like:
Dim objSpeech As Speech.Object
Set objSpeech = New Speech.Object
(forgive me: I don't work with the SDK, so I don't know what you actually
have instead of Speech.Object)
WIth Late Binding, you'd have no reference, and you'd change your code to:
Dim booNoSDK As Boolean
Dim objSpeech As Object
On Error Resume Next
booNoSDK = False
Set objSpeech = CreateObject("Speech.Object"
If Err.Number = 429 Then
booNoSDK = True
MsgBox "Sorry, you don't have the Speech SDK installed"
End If
On Error GoTo ErrorHandler
Now, in the rest of your code, you check the value of booNoSDK, and bypass
the stuff dealing with speech if its value is True.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Thanks for the info guys that got me up and running nicely.
>
[quoted text clipped - 68 lines]
>> > few
>> > others.
BlockNinja - 27 Sep 2006 17:37 GMT
Nah my code is like this:
Option Compare Database
Option Explicit
' This is some utility code that really doesn't serve a functional purpose,
it just gives the capability
' to use the TTS (Text to Speech) capabilities from Microsoft if it's
installed.
Public Function SpeakText(ByVal textToSpeak)
' I normally don't use CreateObject as it's bad for anyone trying to
read my code...
' but here I do because I don't want execution to fail if the user
doesn't have the Speech API (SAPI) installed.
' If it is though, then I create a voice object, set it to the first
voice, and have it speak the text I want.
If DetermineSpeechCapability = True Then
Dim spV, iSpeechTokens
Set spV = CreateObject("Sapi.spVoice")
Set iSpeechTokens = spV.GetVoices()
Set spV.Voice = iSpeechTokens.Item(0)
Call spV.Speak(textToSpeak)
Set iSpeechTokens = Nothing
Set spV = Nothing
End If
End Function
Public Function DetermineSpeechCapability() As Boolean
' Here I just loop through the references and see if the user has a ref
to SAPI
DetermineSpeechCapability = False
Dim i, icnt As Long
icnt = Application.VBE.ActiveVBProject.References.Count
For i = 1 To icnt
If Application.VBE.ActiveVBProject.References.Item(i).Description =
"Microsoft Speech Object Library" And
Application.VBE.ActiveVBProject.References.Item(i).IsBroken = False Then
DetermineSpeechCapability = True
End If
Next
End Function
Obviously checking the references part is useless there since I had to
remove the reference. However, I'd really like to know if the user HAS
Sapi.spVoice first somehow before trying to do a CreateObject, as that would
be preferrable to trying to trap an ErrNumber. Surely there's gotta be a way
to enumerate what COM libs a particular machine has installed.
> Using Late Binding is infinitely preferable. You won't run into versioning
> problems.
[quoted text clipped - 98 lines]
> >> > few
> >> > others.
Douglas J. Steele - 27 Sep 2006 17:52 GMT
There is, but WHY would that be preferable to trapping the error?
The COM objects are all stored in the registry (in HKCR, and in HKLM, I
believe). To list them all, you'd have to traverse through those parts of
the registry. To determine whether a specific one exists, you'd need to know
the GUID associated with the object and look in that part of HKCR\CLSID

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Nah my code is like this:
>
[quoted text clipped - 177 lines]
>> >> > few
>> >> > others.
BlockNinja - 27 Sep 2006 18:18 GMT
Heh, found a link on CodeGuru saying to HKCR\TypeLib just before I saw this
post... yeah, I'll live with catching an ErrNumber (:
Thanks for all the help!
> There is, but WHY would that be preferable to trapping the error?
>
[quoted text clipped - 184 lines]
> >> >> > few
> >> >> > others.