Updating Linked DataBy default, Visual Basic updates linked objects whenever the user saves the source data while editing the linked object. However, Visual Basic currently does not automatically handle changes that other users make to the source file (such as storing a file on a network), nor do such changes currently trigger events in Visual Basic. To control updating in code, use the OLE control's UpdateOptions property, the Updated event, and the Update method. Table 18.5 describes the UpdateOptions property's three settings. Table 18.5 - The UpdateOptions Property Settings
The Updated event occurs when the user edits, closes, or renames the source file while editing the object from within the OLE control. The Updated event also can occur when the OLE control first loads (as at startup) if the source file for the link has changed since the last time that the control loaded. These events occur regardless of the UpdateOptions property setting. However, not all applications notify the OLE control as they are updated. For instance, Microsoft Word does not trigger the Updated event until the user saves or closes the file. Microsoft Excel, however, triggers the Updated event each time a cell of data on a worksheet changes. The Updated event procedure has this form: Private Sub OLE1_Updated(Code As Integer) '... your code here. End Sub The Code argument corresponds to the type of update that occurred. Table 18.6 describes the possible values. Table 18.6 - Possible Values of the Code Argument
Some actions might cause more than one event to occur. For example, if the user closes a file and saves changes, the OLE control receives three Updated successive events: vbOLEChanged, vbOLESaved, and vbOLEClosed. Use the Update method to update linked objects from their source files. In Visual Basic 4.0, Microsoft has changed this method, which in Visual Basic 3.0 used the Action property setting OLE_UPDATE to update links. In Visual Basic 4.0, the Action property still works, but using the Update method makes code clearer and easier to understand. |
||||||||||||||||||||||||||||
![]() |
![]() |
|||