Solved

Setting references problem

Posted on 2004-08-05
5
2,527 Views
Last Modified: 2012-06-27
Hello,

I have a database which includes references to the Word and Excel object libraries. It has been developed in Access2000 format using Office xp (ver 10) and there are no problems running it as-is in Office 03 (ver 11). The problem has come up where someone is running the database in Office2000 (Access has been upgraded to 2002).

I have modified a routine from the MS web site which removes broken references. After that, it figures out the verson of office and resets the references. Code is further below...

When running it on the Office2000 machine I get the following error messages. I'm thinking the version numbers are all wrong...

"Your [database name] database or project contains a missing or broken reference to the file 'msword.olb' Version 8.2"

and

"Your [database name] database or project contains a missing or broken reference to the file 'excel.exe' Version 1.6"

Here's the code...

    Dim loRef As Access.Reference
    Dim intCount As Integer
    Dim intX As Integer
    Dim blnBroke As Boolean
   
    On Error Resume Next

    'Count the number of references in the database
    intCount = Access.References.count
 
    'Loop through each reference in the database
    'and remove broken references
    For intX = intCount To 1 Step -1
      Set loRef = Access.References(intX)
      With loRef
        blnBroke = .IsBroken
        If blnBroke = True Or Err <> 0 Then
          With Access.References
            .Remove loRef
          End With
        End If
       End With
    Next
   
  Set loRef = Nothing

 ' now set the references

If (Dir("c:\Program Files\Microsoft Office\Office11\msword.olb") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office11\msword.olb"
    End With
ElseIf (Dir("c:\Program Files\Microsoft Office\Office10\msword.olb") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office10\msword.olb"
    End With
ElseIf (Dir("c:\Program Files\Microsoft Office\Office\msword9.olb") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office\msword9.olb"
    End With
End If

If (Dir("c:\Program Files\Microsoft Office\Office11\excel.exe") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office11\excel.exe"
    End With
ElseIf (Dir("c:\Program Files\Microsoft Office\Office10\excel.exe") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office10\excel.exe"
    End With
ElseIf (Dir("c:\Program Files\Microsoft Office\Office\excel9.olb") <> "") Then
    With Access.References
        .AddFromFile "C:\Program Files\Microsoft Office\Office\excel9.olb"
    End With
End If

Any ideas on how to fix or improve this?

wileedingo
0
Comment
Question by:wileedingo
  • 3
  • 2
5 Comments
 
LVL 34

Accepted Solution

by:
flavo earned 125 total points
ID: 11731199
Just use late binding rather than early binding and you don’t need to worry about refrences.

Example

Dim oxl as Object
Dim oWord as Object

Set oxl = CreateObject("Excel.Application")
Set oWord = CreateObject("Word.Application")

The use as you always have.  This will work on any version of Excel / Word. The only thing to look out for (and you would anyway with "dynamic refrences" is that you don’t try and use properties / methods that arent available in all versions.

If you are going to use the late binding, then take away the refrences for word and excel, you don’t need them anymore.

Good luck!

Dave
0
 
LVL 1

Author Comment

by:wileedingo
ID: 11731219
Thanks

I ran my code at startup. Would you instead just plug this in where you need to use Excel or Word? Basically, I have two procedures, one which opens a Word doc and the other an Excel file.

 
0
 
LVL 34

Expert Comment

by:flavo
ID: 11731413
Basically where every you have

Dim oxl as Excel.APplication
Dim oWord as Word.Application

Set oXl = New excel.Application
Set oword = new word.aaplication
replace with


Dim oxl as Object
Dim oWord as Object

Set oxl = CreateObject("Excel.Application")
Set oWord = CreateObject("Word.Application")

Dave
0
 
LVL 1

Author Comment

by:wileedingo
ID: 11731510
Sooo much easier. Most excellent help. Thanks muchly.

wileedingo
0
 
LVL 34

Expert Comment

by:flavo
ID: 11733538
To easy mate.

Good luck with your app!

Dave
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now