Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Adding Reference Programatically

Discussion in 'Information Technology' started by BenWeber, Jul 28, 2006.

  1. BenWeber

    BenWeber
    Expand Collapse
    Guest

    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
     
  2. Loading...


  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    Ben the approach you are taking is not going to work. As you already found,
    if the reference is broken, the app won't go.

    For more info, see:
    How to guarantee that references will work in your applications
    at:
    http://www.trigeminal.com/usenet/usenet026.asp?1033

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    news:06B94753-A0C1-4506-BDD9-2591B0BD9DD4@microsoft.com...
    >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
     
  4. BenWeber

    BenWeber
    Expand Collapse
    Guest

    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

    "Allen Browne" wrote:

    > Ben the approach you are taking is not going to work. As you already found,
    > if the reference is broken, the app won't go.
    >
    > For more info, see:
    > How to guarantee that references will work in your applications
    > at:
    > http://www.trigeminal.com/usenet/usenet026.asp?1033
    >
    > --
    > Allen Browne - Microsoft MVP. Perth, Western Australia.
    > Tips for Access users - http://allenbrowne.com/tips.html
    > Reply to group, rather than allenbrowne at mvps dot org.
    >
    > "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    > news:06B94753-A0C1-4506-BDD9-2591B0BD9DD4@microsoft.com...
    > >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

    >
    >
    >
     
  5. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    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

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    news:8F31D4F9-91AB-461E-B7CF-87ADF34EEB06@microsoft.com...
    > 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
    >
    > "Allen Browne" wrote:
    >
    >> Ben the approach you are taking is not going to work. As you already
    >> found,
    >> if the reference is broken, the app won't go.
    >>
    >> For more info, see:
    >> How to guarantee that references will work in your applications
    >> at:
    >> http://www.trigeminal.com/usenet/usenet026.asp?1033
    >>
    >> "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    >> news:06B94753-A0C1-4506-BDD9-2591B0BD9DD4@microsoft.com...
    >> >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
     
  6. BenWeber

    BenWeber
    Expand Collapse
    Guest

    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.



    "Allen Browne" wrote:

    > 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
    >
    > --
    > Allen Browne - Microsoft MVP. Perth, Western Australia.
    > Tips for Access users - http://allenbrowne.com/tips.html
    > Reply to group, rather than allenbrowne at mvps dot org.
    >
    > "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    > news:8F31D4F9-91AB-461E-B7CF-87ADF34EEB06@microsoft.com...
    > > 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
    > >
    > > "Allen Browne" wrote:
    > >
    > >> Ben the approach you are taking is not going to work. As you already
    > >> found,
    > >> if the reference is broken, the app won't go.
    > >>
    > >> For more info, see:
    > >> How to guarantee that references will work in your applications
    > >> at:
    > >> http://www.trigeminal.com/usenet/usenet026.asp?1033
    > >>
    > >> "BenWeber" <BenWeber@discussions.microsoft.com> wrote in message
    > >> news:06B94753-A0C1-4506-BDD9-2591B0BD9DD4@microsoft.com...
    > >> >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

    >
    >
    >
     

Share This Page