Solved

Activate a reference in VBA

Posted on 2007-11-23
5
841 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending email from List Data 2 51
Password on a button in Access 2013 7 35
VBA pass value between two fields different tables 10 38
Search Form not Querying 2 11
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

920 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

15 Experts available now in Live!

Get 1:1 Help Now