?
Solved

Set dll references with vba?

Posted on 2000-03-23
7
Medium Priority
?
561 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 800 total points
ID: 2650927
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
ID: 2650970
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
ID: 2650993
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 7

Expert Comment

by:Believer
ID: 2650998
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
ID: 2651410
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
ID: 2652031
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
ID: 2652099
Glad I could help you tradenut.

Best regards,
Paasky
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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

840 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