Microsoft KB Archive/818367

= HOW TO: Call the Save Method of an MDI Child Form from the MDI Form Toolbar Menu by Using Visual Basic 6.0 =

Article ID: 818367

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-





IN THIS TASK

 * SUMMARY
 * Requirements
 * Call the Save Method in an MDI Child Form
 * Verify That It Works
 * REFERENCES



SUMMARY
This step-by-step article describes how to call the Save method in a multiple document interface (MDI) child form when you click the Toolbar button on the MDI Form.

back to the top

Requirements
The following lists the recommended hardware, software, network infrastructure, and service packs that you must have:

Microsoft Visual Basic 6.0

This article assumes that you are familiar with the following:
 * Microsoft Visual Basic 6.0 IDE
 * Microsoft Visual Basic 6.0 programming

back to the top

Call the Save Method in an MDI Child Form
 Start Visual Basic 6.0. On the File menu, click New Project. In the New Project dialog box, click Standard EXE, and then click OK. In Solution Explorer, right-click Form1, and then click Remove Form1. On the Project menu, click Add MDI Form. In the Add MDI Form dialog box, click MDI Form, and then click Open. Set the Name property of the MDI Form to frmMDI, and then set the WindowState property to Maximized. On the Project menu, click Add Form. In the Add Form dialog box, click Form, and then click Open.

By default, the Form1 form is created</li> Set the MDIChild property of the Form1 form to True, and then set the Borderstyle property of the Form1 form to Fixed Dialog.</li> Add a command button and a text box to the Form. Set the Name property of Command Button to cmdSave, and then set the Caption property to Save.</li> To view the code editor, double-click the Save command button. Change the Click event scope of the 'cmdSave' event handler from Private to Public.</li> Repeat step 5 through step 8 two times. This adds MDI child form Form2 and MDI child form Form3.</li>  Add the following code to the Click event of the Save command button of the MDI child form Form1: MsgBox &quot; Save event of MDI Child Form: Child1&quot; </li>  Add the following code to the Click event of the Save command button of the MDI child form Form2: MsgBox &quot; Save event of MDI Child Form: Child2&quot; </li>  Add the following code to the Click event of the Save command button of the MDI child form Form3: MsgBox &quot; Save event of MDI Child Form: Child3&quot; </li> On the Project menu, click Components. Click Microsoft Windows Common Controls 6.0, and then click OK.</li> Double-click the Toolbar control in the toolbox. Right-click Toolbar, and then click Properties.</li> Click the Buttons tab in the Toolbar Properties dialog box, and then click Insert Button to add a Toolbar button. Set the Caption property of the Toolbar button to Save, and then set the Key property to Save.</li> Click OK.</li> To view the code editor, double-click the Toolbar to open in Code view.</li>  Add the following code to the Click event of the Toolbar: On Error GoTo NoActiveForm Select Case Button.Key Case &quot;save&quot; Me.ActiveForm.cmdSave_Click End Select Exit Sub

NoActiveForm: MsgBox Err.Description </li>  Add the following code to the 'Load' event of the MDI Form frmMDI to show all the MDI child forms when the application starts. Form1.Show Form2.Show Form3.Show </li> On the Project menu, click Project Properties. In the Startup Object combo box on the General tab, click frmMDI as the startup object.</li></ol>

back to the top

Verify That It Works
<ol> <li>On the Run menu, click Start.

The MDI application with three MDI child forms appears. Each MDI child form has a text box and a Save command button.</li> <li>Click Save on the Toolbar while the Form Child3 is active. A message box displays the following message:

Save event of MDI child form: Child3

</li> <li>Randomly make other MDI child forms active, and then click Save on the toolbar to see if the correct child form Save method is called whenever you click Save on the toolbar.</li></ol>

back to the top

<div class="references_section">