Adding Reference Programatically

B

BenWeber

I use the code included below to try to programatically add a reference to
the Office Web Components 10 Object Library: owc10.dll (C:\Program
Files\Common Files\Microsoft Shared\Web Components\10\). This application is
used by multiple people at different sites, so manually going into the code
and adding the reference isn't an option.

My problem is that when i send the app to someone to use, it gives them an
error that they are missing that dll...

I put the code below in the form_open event of the startup form. The actual
form using the reference hadn't been opened at that time. Is something wrong
with my code? Shoudl it be somewhere else? Should i compile it into an exe?
It's hard to debug this because obviously my machine has that code.

Also, it does seem to work on some machines but not others? I'm only
distributing this to users with XP and MS Access 2003... All users have the
DLL, too.



Private Sub Form_Open(Cancel As Integer)
Dim ref As Reference
Dim count As Integer
Dim Found As Boolean

Found = False
For Each ref In References
If ref.Name = "OWC10" Then
Found = True
Exit For
End If
Next

If Not Found Then
FileName = "C:\Program Files\Common Files\Microsoft Shared\Web
Components\10\OWC10.dll"
If Len(Dir(FileName)) = 0 Then
MsgBox ("Unable to find the Office Web Components 10 Library in '" &
FileName & "'.")
Application.Quit
Exit Sub
End If
Set ref = References.AddFromFile(FileName)
End If

End Sub
 
B

BenWeber

So you're suggesting i could solve this with just putting

Declare Function DllRegisterServer Lib "OWC10.DLL"

Somewhere in the app? Where would it go?

What happens if this is already registered?

Thanks,
-B
 
A

Allen Browne

I don't think michka suggested that in his article.

My suggestion would be to avoid using any libraries that are not absolutely
essential.

If you want to do it anyway, and you are absolutely certain that some
version of the Office Web Components will exist on every computer, and that
you will not be calling any functionality that requires a specific version,
you might consider late binding. This should give you a start:
http://support.microsoft.com/kb/260410/en-us
 
B

BenWeber

I don't see how that article speaks to my issue at all, it may just be that i
don't know this all that well like you do.

I also thought that that is what the author suggested, i copied and pasted
that line from the article.

And, i certainly do have to use OWC, if i didn't, i wouldn't have posted
asking how it can be done.

Thanks for your input, but not your tone. I do respect people who try to
help others, and will give you the benefit of the doubt and just assume you
didn't mean to communicate in the manner you did.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top