References

C

Chris Williams

I've developed a database in Access 2003 that has
references to the Outlook and Excel 11.0 object libaries.
this same database needs to be run by users who have the
Office 9.0 equivalent libaries (and Access 2000).
Therefore when they open the database the 11.0 references
are flagged as missing, and the code will not run.

I can detect when the references are missing, and I think
I can write the code to set up the correct references for
the particular version of Office in use. However the code
will be left in an uncompiled state - is there anyway to
compile the code from within code?

Thanks

Chris
 
P

Paul Overway

You need to compile on a system with the Office 9.0 libraries....or use late
binding, i.e., CreateObject. Late binding is marginally slower, but has the
advantage of not requiring a reference at all and allows you to trap an
error in the event that the target PC does not have Outlook or Excel
installed.

'Sample code

Dim x as object
Dim y as object

On error resume next

Set x = CreateObject("Outlook.Application")

If err.number = 429 Then
Msgbox "Outlook is not installed."
Exit Sub
End if

Set y = CreateObject("Excel.Application")

If err.number = 429 Then
Msgbox "Excel is not installed."
Exit Sub
End if

Note that you can use a reference during development and change your
declarations to the actual type to provide for intellisense, but you'll need
to remove the reference and change the type to Object before compile. Also,
an actual value must be used in place of any enum constants derived from the
library.
 
C

Chris Williams

Thanks for your help

Chris

-----Original Message-----
You need to compile on a system with the Office 9.0 libraries....or use late
binding, i.e., CreateObject. Late binding is marginally slower, but has the
advantage of not requiring a reference at all and allows you to trap an
error in the event that the target PC does not have Outlook or Excel
installed.

'Sample code

Dim x as object
Dim y as object

On error resume next

Set x = CreateObject("Outlook.Application")

If err.number = 429 Then
Msgbox "Outlook is not installed."
Exit Sub
End if

Set y = CreateObject("Excel.Application")

If err.number = 429 Then
Msgbox "Excel is not installed."
Exit Sub
End if

Note that you can use a reference during development and change your
declarations to the actual type to provide for intellisense, but you'll need
to remove the reference and change the type to Object before compile. Also,
an actual value must be used in place of any enum constants derived from the
library.


--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com





.
 

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