Working with External References

Working with external references usually means either adding ActiveX controls to your forms or using external type libraries to do things that aren't part of the object model for the program you're using. The Microsoft Web Browser control, for example, is an ActiveX control commonly added to forms, whereas a reference to one of the Microsoft ActiveX Data Objects (ADO) libraries might be used to provide easy access to data sources.

3"

Writing Microsoft Project Code with Visual Basic for Applications Using ActiveX Controls

Working with ActiveX controls is probably the easiest way to use external references. Controls that have been registered on your computer (this happens automatically when controls are installed on your computer) appear in the Additional Controls dialog box (click Tools, Additional Controls) and can be added to the Toolbox. After a control appears in the Toolbox, you can use it just as you would any of the intrinsic controls in the Microsoft Forms library that is included with Microsoft Project.

All ActiveX controls have common properties for a name, physical dimensions and position, tab order, and so on, in addition to whatever properties and methods they supply as part of their specialized functionality. All the general information you know from working with the intrinsic controls also applies to new controls, enabling you to concentrate on working with the new capabilities the control provides.

Note Many ActiveX controls also have type libraries associated with them, which appear in the object browser. These libraries might be listed in the Library box by the filename of the library instead of by the name of the control as it appears in the Additional Controls dialog box.

Using External Libraries

An external type library (sometimes called a "helper library") is really nothing more than an object model that doesn't have a visual element and doesn't represent the Visual Basic aspect of another program. Type libraries are installed in association with a program or the operating system.

After you add a reference to a library (click Tools, References), the objects, methods, properties, events, and constants defined in the library appear in the object browser. There are no special rules for working with an external type library and you can use its members as you would the members of the Microsoft Project object model.

The following code is an example of working with an external type library. It uses the Microsoft ActiveX Data Objects 2.6 Library to access the values of certain fields for each record in a Jet (Microsoft Access) database:

Sub ReadDataFile(strFileName As String)

' The Connection object is found in the ADO library ' The New keyword in a variable declaration creates an object ' reference at the same time as the variable is declared Dim conData As New Connection

' The Recordset object is found in the ADO library Dim rstTopic As New Recordset Dim strSelect As String Dim bytCount As Byte

' Connect to data source

' ConnectionString is a property of the Connection conData.ConnectionString = "Provider=Microsoft.Jet

strFileName object

.OLEDB.4.0;Data Source=

' This Open method is for the Connection object conData.Open

' Select the records and open a recordset strSelect = "SELECT * FROM Topic" ' This Open method is for the Recordset object rstTopic.Open strSelect, conData

' Move to the first record in the Recordset object rstTopic.MoveFirst

' Read through each record to find the values I want For bytCount = 1 To rstTopic.Fields!byt1.Value rstTopic.MoveNext

' gudtText is a global, user-defined collection object gudtText.blnNumbered.Add rstTopic.Fields!byt1.Value gudtText.bytMatchNode.Add rstTopic.Fields!byt2.Value gudtText.bytNumber.Add rstTopic.Fields!byt3.Value gudtText.strText.Add rstTopic.Fields!str2.Value Next bytCount

' Close the reference to the Connection object conData.Close

' Clean up the object references Set rstTopic = Nothing Set conData = Nothing End Sub

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment