Set dll references with vba?

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!
tradenutAsked:
Who is Participating?
 
paaskyConnect With a Mentor Commented:
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
 
SnoopDoggCommented:
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
 
BelieverCommented:
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
BelieverCommented:
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
 
rgudgeonCommented:
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
 
tradenutAuthor Commented:
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
 
paaskyCommented:
Glad I could help you tradenut.

Best regards,
Paasky
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.