• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 31. Exchanging Data with Automat... > Using Automation Servers with Access...

Using Automation Servers with Access 97

To use Automation, you must first write the code to create an instance in your application of the object that you plan to program. Access VBA contains the following four reserved words that you use to create an instance of a programmable object with Access VBA code:

  • The Object data type is assigned to the programmable object variables you declare with {Private|Dim|Public} objName As Object statements. The Object property of a programmable Automation object contained in a bound or unbound object frame control points to the instance of the object. You can assign to an Object variable a pointer to the Automation object with the general syntax

    								Set objName = [Forms!frmName!]uofName.Object
    
  • The CreateObject function assigns a pointer to a new instance of an empty programmable object, such as a blank Excel 97 Worksheet object. The general syntax of the CreateObject function is

    								Set objName = CreateObject("ServerName.ObjectType")
    
  • The GetObject function assigns a pointer to a new instance of a programmable object whose data is contained in an existing file, strPathFileName, in the following syntax example:

    								Set objName = GetObject(strPathFileName[, _
       "ServerName.ObjectType"])
    

    You can omit the ServerName.ObjectType argument if an entry in the Registry associates the file's extension with the object of the application you want to program. In the case of Excel 97, the default object type for .xls files is Excel.Workbook. If you substitute an empty string ("") for strPathFileName, the preceding statement assigns a pointer to an object of ServerName.ObjectType if such an object is open. If an object of the specified type is not open when the statement is executed, a trappable error occurs.

  • The New keyword declares an Object variable and assigns in a single command a pointer to a new instance of an empty programmable object, such as an empty Word 97 document. The general syntax for creating an instance of a programmable object with New is

    {Private|Dim| Public|Static} objName
    								As New [ServerName.]ObjectType
    							

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint