Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Activate a reference in VBA

Posted on 2007-11-23
5
Medium Priority
?
873 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 1200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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