Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set dll references with vba?

Posted on 2000-03-23
7
Medium Priority
?
556 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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