DAOCTL: ActiveX Control Container with Data Bound Controls

Click to open or copy the DAOCTL project files.

This sample shows how to build an ActiveX control container that contains data bound controls. The container provides the controls with data from a Microsoft Access database via DAO.

To build the sample requires you to first build AccsPict and Control, which are two ActiveX controls found in the subdirectories beneath DAOCTL. Open a Project Workspace, go into each subdirectory and choose the .mdp file, then on the Build menu, click Build accspict.ocx or Build daoedit.ocx. If you are building this sample on Windows® 95, you should build the non-Unicode versions

Run the application and click DAO to open a data source. The sample database Sampdata.mdb is in the DAOCTL directory.

Once you have a database open, you will be able to use the tree control to navigate through the database structure. When you are at the "field" level, you can double-click any of the fields represented by a green color. The field chosen will then be dynamically bound to one of the ActiveX control edit fields below the tree control. Additionally, if a field contains a Microsoft Access object field that in turn contains an Access picture, it will be displayed on the right of the tree in the Access Picture ActiveX Control. You can move to the next or previous record using the spin buttons in the lower right corner.

Changing the contents of an edit field and tabbing out of that field will reflect your change in the database.

Points of Interest

Of particular interest is the way the ActiveX controls notify the container of changes made. This happens in two stages:

First, when a key is pressed while one of the edit controls has focus, the edit control will make a call to the function BoundPropertyRequestEdit. This call requests authorization from the container to allow changes to the data contained in the control. Only if this is granted will the key be allowed to pass through.

Finally, assuming that permission is granted, the control will call BoundPropertyChanged when the control loses focus. This notifies the container that the data has changed and should be stored in the database.