Solved

Activate a reference in VBA

Posted on 2007-11-23
5
839 Views
Last Modified: 2013-12-05
Experts,

I have an ADP application, and our application is used by several users with several versions of outlook.  (2003-2007) now to avoid conflicts, I would like to add a function in my sendemail routine, that adds the reference (depending on the outlook version), and activate them.

I have the function to add them...

But as soon as the reference is added, I doesn't find how to activate it ?
So my solution would be something

if reference exist....
if outlook version = ....
  active reference 12
else
 active reference 11
end if
execute sendmail code

Thanks in advance

ITSupport.bnl
Function ReferenceFromFile(strFileName As String) As Boolean

      Dim ref As Reference
 

      On Error GoTo Error_ReferenceFromFile

      ' Create new reference.

      Set ref = References.AddFromFile(strFileName)

      ReferenceFromFile = True
 

Exit_ReferenceFromFile:

      Exit Function
 

Error_ReferenceFromFile:

      MsgBox Err & ": " & Err.Description

      ReferenceFromFile = False

      Resume Exit_ReferenceFromFile

End Function

Open in new window

0
Comment
Question by:ITBenelux
  • 2
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 300 total points
ID: 20338721
This isn't the recommended method; you'd be much better advised to use Late Binding, or simply allow Access to handle this for you.

To use Late Binding, you'd change your Outlook code as such:

Dim objMail As Outlook.MailItem

to

Dim objMail As Object
Set objMail = CreateObject("Outlook.MailItem")

This would build the item in whatever version of Outlook is installed on the machine.

Or, if you want to leave Early Binding in place, then build the application on a machine with the "lowest common denominator" (or LCD) installed (i.e. Outlook 2003) and ship that to your users. Access will automatically "upsize" the reference for those users running Outlook 2007. In general, this is a recommended process for ANY development platform - you simply MUST work to the LCD in your code, else you run the risk of using a feature that is NOT available in an earlier version ...
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 20338737


you can always use:
Dim Outobj as Object

instead of of
Dis OutObj as Outlook.application

this would work for all Outlook versions.

jaffer
0
 
LVL 1

Author Comment

by:ITBenelux
ID: 20339426
If I change dim outobj as outlook.application than still all other related objects are not working without a reference
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

so Will the the function still work if I all set them to object, and when I have no reference to microsoft oulook object ?

I will test LSMconsulting approach tonight...
0
 
LVL 84
ID: 20339940
Yes, you must change every reference to any Outlook object, and then remove the Outlook reference.
0
 
LVL 1

Author Closing Comment

by:ITBenelux
ID: 31410661
Problem solved.. thanks
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

20 Experts available now in Live!

Get 1:1 Help Now