Adding references in Access project

M

Marc

Hi,

In order to use the Pivot table programatically, I had to include the
Microsoft Office XP components reference to my project.

This worked well with the application run on my computer. But when I
distributed the application, other users get "broken reference to the file
'OFFOWC.DLL' "message.

Obviously, I can't get ask other users to open the debugger and add this
reference manually.

How do I ensure that the references are distributed with my application ?

Can I have the reference package added programatically ?

Thanks in advance


Marc
 
R

Roger Carlson

On my website (www.rogersaccesslibrary.com), is a small Access database
sample called "SetReferenceToDAO.mdb" which might help. I used this to set
a reference to DAO in a programmatically created database (back when A2000
and A2002 didn't have DAO as default). You should be able to modify it for
your situation. You can find it here:
http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=270.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
J

joshua A. Booker

Hi Marc,

The Access Application Object has a references collection. Each Refernce
Object has a AddFromFile method. I use this to add refs to library mde
files joining multiple Access apps together in the same application.
You need to handle a couple possible errors such as if a reference allready
exists with the same name. In which case you can remove and add it again.
I would suggest you distibute the application with you own copy of the .dll
and add a reference to the.dll in your directory. This is because each
machine might have office installed in different directories.

Here is the code I use to add references.


Function NewReference(strFile As String) As Boolean

'Code by JB 120700
'Adds new reference to references collection from path name argument
'Returns True if success; False if error

On Error GoTo Error_NewReference
Dim ref As Reference
NewReference = True

Set ref = References.AddFromFile(strFile)
NewReference = True

Exit_NewReference:
Exit Function
NameConflict:
If vbYes = MsgBox(prompt:="The Module that you are attempting to
reference has the same name as an existing reference." & vbCrLf & "" &
vbCrLf & "Do you wish to replace the existing reference?", _
Buttons:=vbExclamation + vbYesNo + vbDefaultButton1, _
Title:="Module Name Conflict") Then
'ReplaceReference (strFile)
End If
GoTo Exit_NewReference

Error_NewReference:
If Err = 32813 Then
If Loading Then
NameConflict = True
Resume Exit_NewReference
Else
Resume NameConflict
End If
End If
NewReference = False
If Err = 35021 Then
MsgBox Err.Description & vbCrLf & "The file that you are trying to
reference may not be compiled."
Else
MsgBox Err & ": " & Err.Description, , "New Reference Error"
End If
Resume Exit_NewReference
End Function

HTH,
Josh
 
P

Paul Shapiro

Others gave you suggestions on code to manipulate references. But if your
users don't have the Office OWC component installed, they can't run your
program no matter what references you add. If any reference is missing, no
code can compile.

If the features that rely on that component are not the essential core of
your application, you can change the Dim statements in your code to just
dimension the variables as Object and remove the reference from your own
application. Use CreateObject to instantiate the objects. If the user's
computer can't instantiate the requested object you can trap the error and
give a friendly message like "Using this feature requires you to install the
Microsoft Office Web Components". You can find more info by searching on
"Late Binding". This way all of your code compiles and runs, and only the
functionality that uses those components fails.
 
M

Marc

Thank you all.

Following Paul's advice, I change two Dim statements replacing PivotFieldSet
and PivotTotal with Object.

Also, replaced a constant plFunctionSum with its value, 1.

The code compiles and works after I removed the reference to Office XP Web
components.

Will distribute it later today and trust it will work.

Regards
 

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

Similar Threads


Top