Solved

Set dll references with vba?

Posted on 2000-03-23
7
478 Views
Last Modified: 2010-11-15
Is there a way in VBA to set a reference to an object library in Access97?

I need to set a reference to the Outlook object library without going to each machine and using Tools/References to set it.  I know the name and location of the file I need to set, I just can't find any help in the knowledge base.

Anyone have any ideas?

Thanks!
0
Comment
Question by:tradenut
7 Comments
 
LVL 10

Accepted Solution

by:
paasky earned 200 total points
Comment Utility
Hello tradenut,

This is from Access help:

The following example creates a reference to a specified type library:

Function ReferenceFromFile(strFileName As String) As Boolean
      Dim ref As Reference

      On Error GoTo Error_ReferenceFromFile
      Set ref = References.AddFromFile(strFileName)
      ReferenceFromFile = True

Exit_ReferenceFromFile:
      Exit Function

Error_ReferenceFromFile:
      MsgBox Err & ": " & Err.Description
      ReferenceFromFile = False
      Resume Exit_ReferenceFromFile
End Function

You could call this function by using a procedure such as the following, which creates a reference to the calendar control:

Sub CreateCalendarReference()
      If ReferenceFromFile("C:\Windows\System\Mscal.ocx") = True Then
            MsgBox "Reference set successfully."
      Else
            MsgBox "Reference not set successfully."
      End If
End Sub

Hope this helps,
Paasky
0
 

Expert Comment

by:SnoopDogg
Comment Utility
Access 97 exposes the references through the "Application.References" object.  This code will print the name and full path to the file of all references currently set:

dim myref as reference
for each myref in application.references
   debug.print myref.name
   debug.print myref.fullpath
next

Add Outlook to the references on you machine and this will display the full path.  The Outlook 8.0 references a file called "msoutl8.olb"  Since the paths to it may be different on different machines, you may need to code to search for it.  Once you get the full path, you can add it to the references with:

Application.References.AddFromFile "C:\Program Files\Microsoft Office\Office\msoutl8.olb"

Hope it helps...
Snoop
0
 
LVL 7

Expert Comment

by:Believer
Comment Utility
Here's a routine I stole from Microsoft for importing calendar items to a table...

Public Sub GetAppointments(strCriteria As String)
   Dim objOutlook As New Outlook.Application
   Dim objNS As NameSpace
   Dim objInboxItems As Items
   Dim Appt As Object
   'Dim Criteria As String
   Dim db As Database
   Dim rst As Recordset
   
   
   Set objNS = objOutlook.GetNamespace("MAPI")
   
   'Get all items in Calendar folder
   Set objInboxItems = objNS.GetDefaultFolder(olFolderCalendar).Items
   
   'Criteria for Find method
   'Criteria = "[Start]>""2/15/98"" and [Start]< ""3/1/98"""
   'Omit recurring apointments
   strCriteria = strCriteria & " and [IsRecurring]=False"
   
   'Find first Appointment matching the criteria
   Set Appt = objInboxItems.Find(strCriteria)
   
   'Loop until no match
   Set db = DBEngine(0)(0)
   Set rst = db.OpenRecordset("Calendar")
   Do While Not (Appt Is Nothing)
      'Print the Appointment Start, End, and Subject
      'Debug.Print Appt.Start; Appt.End; Appt.Subject
      'Write a new Record
      With rst
         .AddNew
            !Subject = Appt.Subject
            !StartDate = Format$(Appt.Start, "Short Date")
            !StartTime = Format$(Appt.Start, "Long Time")
            !EndDate = Format$(Appt.End, "Short Date")
            !EndTime = Format$(Appt.End, "Long Time")
            '!AllDayEvent = Appt.AllDayEvent
            '!Reminderonoff = Appt.ReminderSet
            '!ReminderDate=Appt.
            '!ReminderTime=Appt.
            '!MeetingOrganizer=Appt.
            '!RequiredAttendees=Appt.
            '!OptionalAttendees=Appt.
            '!MeetingResources=Appt.
            '!BillingInformation = Appt.BillingInformation
            '!Categories=Appt.
            !Description = Appt.Body
            '!Location=Appt.
            '!Mileage=Appt.
            '!Priority=Appt.
            '!Private=Appt.
            '!Showtimeas=Appt.
         .Update
      End With
      'Find the next Appointment matching the same criteria used with the Find method
      Set Appt = objInboxItems.FindNext
   Loop
   
   Set Appt = Nothing
   Set objInboxItems = Nothing
   Set objNS = Nothing
   Set objOutlook = Nothing
End Sub

I happen call it with a date range like this: Call GetAppointments("[Start]>=""3/16/2000"" and [Start]< ""3/18/2000""")

If it ain't too purdy, it's cuz it's a tool I use for me, myself, and I to transfer Outlook appointments into our billing system.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Expert Comment

by:Believer
Comment Utility
Oops, guess I *do* still have a "hard" reference to msoutl85.olb, "Micorsoft Outlook 98 Object Model"... thot I didn't :(  But you should still be able to avoid the hard reference!  (ahem.)
0
 

Expert Comment

by:rgudgeon
Comment Utility
I use the following on my machine to find the correct name for the reference I am looking to set

For intI = 1 To References.Count
    Set ref = References(intI)
    MsgBox "Reference is " & ref.Name
Next intI

This will display the name of each reference and give you the correct name to use in the following routine in your production program

' set a reference to the registry manipulation dll if necessary
If Not FindReference("regObj") Then
    If Not ReferenceFromFile(gblstrSysPath & "regObj.dll") Then
        DoCmd.Quit
    End If
End If

This set the reference to regObj in the Windows System path. You need to use the correct path to the library or dll. most are in the win system path

You need to be aware with this, though, if there are instructions in your startup code that depend on this reference and if the code is compiled when the user starts the app a compile error will occur. the problem is that the reference must be set before the module will compile and the module hass to run to set the reference - Catch 22!

Regards
Ray
0
 

Author Comment

by:tradenut
Comment Utility
Thanks to everyone who commented, I really appreciate the help!

Paasky gets the points as he was the first to get the answer.

And also thanks to Ray for pointing out that the reference needs to be set before the application is run.  That's going to save me some time in the morning!

-Regards
0
 
LVL 10

Expert Comment

by:paasky
Comment Utility
Glad I could help you tradenut.

Best regards,
Paasky
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now