Setting Object References

 < Day Day Up > 

Automation clients need a way to determine which objects they can use from any given automation server. This information is stored in files called type libraries, which normally have a .tlb or .olb extension. A type library contains information on:

  • Objects

  • Methods

  • Properties

  • Events

Although it's not absolutely necessary to use a type library to use objects from an automation server, it's normally a very good idea. For one thing, without using the type library, you don't get the benefits of IntelliSense or the Object Browser when writing automation code. So, we recommend that you always use a type library. To use a type library for automation, you need to set a reference to the type library. Here's how to do that for the Microsoft Word and Microsoft Excel type libraries that you use in this chapter:

  1. Open the Visual Basic Editor by pressing Alt+F11 from Access.

  2. Choose Tools, References to open the References dialog box, shown in Figure 21.1.

    Figure 21.1. Adding a reference to a type library.

    graphics/21fig01.jpg


  3. Locate the Microsoft Excel 11.0 Object Library and the Microsoft Word 11.0 Object Library in the list of available references, and click the checkbox for each of them.

  4. Click OK to add references to these type libraries to the current Access database.

After you've added a reference to a type library, you'll find that type library's objects in the Object Browser. Press F2 to open the Object Browser, and then choose the type library you want to inspect from the Project/Library combo box. Figure 21.2 shows some of the objects in the Excel type library. You can see that these objects deal with such things as cells and charts, even though you're inspecting the type library from within an Access database.

Figure 21.2. Using Object Browser to inspect a type library.

graphics/21fig02.jpg


NOTE

There's nothing really different about using the Object Browser on Access itself; it's still looking at a type library. The only difference is that Access automatically sets a reference to its own type library.


     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net