Re: Setting a reference to a libray in code

Tech-Archive recommends: Speed Up your PC by fixing your registry



Unifortunately althought Ref.IsBroken is showing as True i cant use
References.Remove Ref it shows an error.

I should point out though that this does work in my ADP on 2007 i.e. i can
remove them if i choose and then add them back which i did for test purposes.
As soon as the reference is missing though it fails you cant remove it
because it is missing and cant add it because it conflicts with one that
already exists, yet its broken!!!

Anyway, we have gone for late binding solution now as it seems the best
option, will put an arror message out if excel or word doesnt exist on the
users machine.

Thanks very much for your help.

Paul

"Paul Shapiro" wrote:

I used to use code similar to what you had in the beginning of this thread
to replace broken references with downlevel references. But I don't think
it's working now. There are a few properties you can read for a broken
reference. Here's the code that used to work. If the ref.isBroken line is
throwing an error, you could catch that error and thereby know that the
reference is broken. The trick then is to know the correct guid's and
version numbers to try for adding the downgraded version references.

Alternatively, you can distribute the application in the oldest version in
use. Office references are generally upgraded automatically to the newer
version. I use Virtual PC to keep one or more virtual machines with the os
and office versions that I need to distribute. You can manually adjust the
references in the VM, and then distribute a "clean" version for users with
older software.

For Each ref In Access.References
strGUID = ref.Guid
'Unfortunately, this seems to fail on the next line when a reference
is broken.
If ref.IsBroken Then
'Print the available details for broken reference
Debug.Print "Reference: " & strGUID _
& " (Broken) v." & ref.Major & "." & ref.Minor
Select Case strGUID
Case "{00062FFF-0000-0000-C000-000000000046}"
'Outlook 9.3 (Office 2007) - try using Outlook 9.2 (Office
2003)
References.Remove ref
References.AddFromGuid strGUID, 9, 2
Case "{00020905-0000-0000-C000-000000000046}"
'Word 8.4 (Office 2007) - try using Word 8.3 (Office 2003)
References.Remove ref
References.AddFromGuid strGUID, 8, 3
Case "{00020813-0000-0000-C000-000000000046}"
'Excel 1.6 (Office 2007) - try using Excel 1.5 (Office 2003)
References.Remove ref
References.AddFromGuid strGUID, 1, 5
'ElseIf Len(Dir(ref.FullPath)) > 0 Then 'Cannot read FullPath
when ref is broken
' References.AddFromGuid strGUID, ref.Major, ref.Minor
Case Else
strMsg = "Reference " & strGUID & " cannot be found." & _
vbCrLf & vbCrLf & "Please contact the programmer."
Beep
MsgBox strMsg, vbCritical, "Cannot run the program"
End Select
End If
Next ref


"Syvers" <Syvers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:11B5FDB7-EA7E-4C2B-BD1D-9B527D1E0A30@xxxxxxxxxxxxxxxx
Hi Douglas

I should have mentioned i tried that method References.Remove Ref but it
does not recognise the ref as existing, i.e. i cant even get ref.name,
seems
like a complete catch 22. Cant add because it exists, cant remove because
it
cant be found!!

Anyway, have been chatting to a colleague about late binding and although
we
are nearly at the end of our application development we think it best to
review all references to word and excel and use the CreateObject(".....")
method aka late binding.

Thanks for your help and advice

Paul


"Douglas J. Steele" wrote:

When a reference is broken, you can't access most of its properties.
However, there's no reason why you can't delete it. Inside your If
statement, use the Remove method of the References collection:

For each ref in References
if ref.isbroken then
References.Remove ref
end if
next ref

That having been said, I'd recommend strongly against trying to reset the
references such as you are. Use Late Binding instead, so that you don't
need
to set a reference, and it'll work with any version of Word or Excel
unless,
of course, you're using features that only exist in a particular version.
Even in that case, though, resetting the reference won't work if the
referenced version doesn't have the feature.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Syvers" <Syvers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4123B40C-7811-4BBA-90A9-FF59A908CF4E@xxxxxxxxxxxxxxxx
Hi

I am trying to reset references to Excel and Word from Access 2007 i.e.
code
developed on 2007 with office 2007 but when dstributed to users the
reference
is broken because they are on say office 2000.

What i do is look through the references to see if any are broken (i
already
know the excel one is though by looking at tools > references) so

For each ref in References
if ref.isbroken then
'fix the reference
end if
next


.



Relevant Pages

  • Re: Setting a reference to a libray in code
    ... I should have mentioned i tried that method References.Remove Ref but it ... Cant add because it exists, ... review all references to word and excel and use the CreateObject ... to set a reference, and it'll work with any version of Word or Excel unless, ...
    (microsoft.public.access.formscoding)
  • Re: "Time and Billing" database question -- access
    ... Invoice" Form comes up propperly, and the Project ID and name display ... > The forms ref works fine also. ... > the main forms references (so, all those other posts about trying to fix the ... > Albert D. Kallal ...
    (microsoft.public.access.gettingstarted)
  • Re: Setting a reference to a libray in code
    ... Hi Douglas, yeah i had already tried that code but got an error message along ... I should have mentioned i tried that method References.Remove Ref but it ... review all references to word and excel and use the CreateObject ... and it'll work with any version of Word or Excel ...
    (microsoft.public.access.formscoding)
  • Re: Kensington runestone Vegetation)in the Scandinavian press
    ... > Doug Weller wrote: aiuob11m0bo8qvlubrhejnpjj45d0sbrg0@xxxxxxx, ... >>> in other words read the ref to medieval documents which are given as ... >> If you have specific references, ...
    (sci.archaeology)
  • Re: Office 2003 SP3 broke my vba code "user-defined type not defin
    ... Compile error: ... Here are the References you asked about... ... The same database run on an Office2003 SP2 machine works fine. ... For Each ref In Access.References ...
    (microsoft.public.access.modulesdaovba)