
July 22nd, 2003, 03:51 PM
|
|
Junior Member
|
|
Join Date: Jul 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Probably the easiest way is to use the Data Environment Designer. You need to have ADODB installed. Add a reference to the Microsoft Data Environment Instance to your project (Project->References). Also add a reference to the Microsoft ActiveX Data Objects. In your project explorer, right click on the Data Environment and select view Object. In the new window, right click on the Data Environment object and select Add Connection. Right click on the new Connection and select Properties. In the dialog, select your Access database.
Now, right click on the connection you just created and select Add Command. Right click on the new Command and select Properties. For Database Object, select Table. Select your main table (machines) as the Object Name and apply.
Right click on the Command and select Add Child Command. Right click on the new child command and select properties and select your related table (machine parts) the same way you did the parent table. Click the Relation tab. If the two tables have a field name in common (like MachineID) it will already be shown for both tables - otherwise, select the related fields. In either case, click Add to add the relationship and apply.
Now, your two tables are related. I would use the Hierarchical FlexGrid for display (Right click on toolbox->components->Microsoft Hierarchical Flexgrid (OLEDB).
Place a FlexGrid on the form and select it. Hit F9 (Properties). In properties set the DataSource property to your Data Environment Object from the drop down and set the DataMember property to the command object for your Parent table.
Now right click on the grid and select Retrieve Structure. Now right click on the grid and select properties (it's different from hitting F9) These are the special properties for the FlexGrid. Here on the Bands tab, you can select which fields to display. Band 0 will be your Parent table and band 1 will be the sub table fields.
When you run the project, the grid will be populated and you can click the Plus/Minus signs on each row to shoe/hide the sub table fields for each machine.
Whew! Hopefully, I haven't left out any important steps. You could do this all theough code, of course, but using the Data Environment Designer takes care of all the dirty work for you, it's all point and click.
You can use other data controls DataCombo, etc. (Make sure to select the OLEDB versions), but you may have to write some code to synchronize them as you move through the parent table.
|