?
Solved

Activate a reference in VBA

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

770 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