Adding Code to Your Form

Before your new form can be used to do anything, you must write event procedures for the ^

controls on it. For the form created in the previous section, you need to write code only for a-

the two buttons. o

The button cmdCancel needs code to close the form's window, in case the user doesn't want to use the form. The quickest way to open the Code window for a form or control is to doubleclick the item while in design mode. If you double-click the Cancel button on the form, the Code window opens to the cmdCancel_Click() event procedure. Type the following code into the Cancel button's vClick event:


Note The Me keyword

The Me keyword always refers to the class (a form is a kind of class) in which it is used. Instead of frmWelcome.Hide, for example, you could simply use Me.Hide.

The cmdOK button is where all the action is for this form. The OK button takes the name the user entered in the txtName box and adds it to the status bar at the bottom of the Microsoft Project window.

With the Code window open, click cmdOK in the Objects box to gain access to the cmdO K_Click() event. Type the following code into the OK button's Click event:

Application.StatusBar = "What would you like to do now, " & _ txtName.Text & "?"

This code sets the Application object's StatusBar property to be the text in quotes, plus the value of the txtName box's Text property.

Because you want the form to close after the user clicks the OK button, add the same code you added to the Cancel button's Click event:


Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment