Solved

Activate a reference in VBA

Posted on 2007-11-23
5
860 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 85

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 85
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

688 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