SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 184 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


Cleaning Up
We??™ve almost got a complete application finished. Let??™s finish off by adding code to our Cancel
button and putting some cleanup code in our form??™s Terminate event.
Add the following line of code to the cmdCancel button??™s Click event:
Private Sub cmdCancel_Click()
Unload Me
End Sub
This single line of code simply unloads the form without saving any values.
Now we??™ll clean up the objects used by our HRWizard UserForm. Add the following to the
UserForm_Terminate event handler:
Private Sub UserForm_Terminate()
Set m_oEmployee = Nothing
Set m_oLM = Nothing
Set m_oWizard = Nothing
End Sub
Now let??™s add a simple function to our project to open the Wizard form. In the VBE, add
a standard module. Add the following method to the standard module:
Sub StartWizard()
HRWizard.Show
End Sub
This single line of code will display the UserForm when it is run.
Testing the HRWizard Application
It??™s time to take our wizard for a test ride. Let??™s enter some data into each screen of the wizard
and save it to the EmpData worksheet.
CHAPTER 4 n USERFORMS 188
From the Excel workbook, run the StartWizard subroutine from the Macro dialog box, as
shown in Figure 4-34.
Figure 4-34. Running the StartWizard macro
Figures 4-35 to 4-39 show some sample input values and the saved data on the EmpData
worksheet.
Figure 4-35. Personal information added
CHAPTER 4 n USERFORMS 189
Figure 4-36. Address information added
Figure 4-37. Equipment information added
CHAPTER 4 n USERFORMS 190
Figure 4-38.


Pages:
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196