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 99 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

The ???Record has been updated??? message
will appear.
To test your success, select and delete all the data from Sheet1 (or just change Kevin??™s
marital status to any character), and run the GetEmpList subroutine again. Your display should
look like Figure 2-30.
Figure 2-30. Employee data after update
Of Excel, Data, and Object Orientation
Earlier in this book, I promised that we??™d see object-oriented solutions to our coding problems
in Excel 2007. Let??™s take our manager list??“creation code and the code that lists a manager??™s
staff, and convert them to classes. Normally, this is the way I would directly approach a solution,
but up to this point we??™ve been exploring some of the VBA possibilities in Excel 2007.
Open DataAccessSample04.xlsm and save it as DataAccessSample06.xlsm.
Open Module1 in the VBE and review the GetManagerList subroutine. We can break its
functionality down to just a few items. The problem with that is it??™s doing a number of unrelated
things. It??™s setting up the worksheet for data import, opening a connection to the
database, getting data, putting it on the worksheet, and then formatting and cleaning up
the worksheet.
When we build our objects, we will pay strict attention to the separation of functionality.
The rule of thumb is that objects should do only one well-defined job. Of course there are
exceptions, but if you plan carefully, you will develop objects that provide a clearly defined
set of methods and properties, providing a focused set of functionality.


Pages:
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111