Microsoft Office 2000 Developer |
When you use the Data Environment in VBA to create a data source, the DataEnvironment object that you create is a publicly creatable object. A publicly creatable object is an object that can be created (or referenced) by another application. The application can then use the object's public functions and properties. (In contrast to a private function or property, which is only usable by the object and is inaccessible to other applications.)
Similarly, you can directly reference a DataEnvironment object and access its public functions and procedures. But first, you must create the DataEnvironment object, then wrap the object in a DLL file. This topic demonstrates how to create a public function for the DataEnvironment object and how to create the DLL file.
For more information about creating the DataEnvironment object, see Creating a Data Source Using the Data Environment Designer. For information about using the DLL and creating an instance of the DataEnvironment object, see Using the DLL in an Office Application.
In Office 2000 Developer, in order to use the Data Environment as a data source in your Office application, it must be compiled as a DLL file, which is done using the Make command of the Visual Basic Editor. Once this is done, the DLL is portable — after being registered on a machine, it can be used from any application. (The DLL is registered automatically on the development machine when it is compiled. When you use the Package and Deployment Wizard to distribute a project, the DLL will also be registered on any machine that uses the Setup.exe program.)
To compile the DataEnvironment object as a DLL
The following example returns a specific recordset named rsCustomers from the DataEnvironment object.
Public Function ReturnRS(rsName As String) As Recordset
Select Case rsName
Case "Customers"
If deNwind.DataEnvironment1.rsCustomers.State = adStateClosed Then
deNwind.DataEnvironment1.rsCustomers.Open
End If
Set ReturnRS = deNwind.DataEnvironment1.rsCustomers
Case Else
' Handle unknown cases here
End Select
End Function
More information about creating DLL files can also be found in the MSDN Library. See Creating an ActiveX DLL in the Component Tools Guide of the Visual Basic documentation.