CHAPTER 4 n USERFORMS 137
Figure 4-4. UserForm with controls placed
As you can see, we??™re designing a very simple data collection tool. We??™re going to write a
record to the database that is stored on Sheet1 in the UserForm workbook, and we want to do
some validation of the data before we save.
Before we begin, we need to think about a couple of functions we might need and how to
approach our code design. First, our form needs to know which worksheet to save the data to
(in this case, Sheet1 contains our database). It also needs to know the next available ID number
and the location of the next available row to place the data when we save the data.
A function that can tell us where the next available row in a worksheet is might be useful
in another project as well. Remember the cExcelUtils class we started in Chapter 2? Let??™s put
our function in that class and export it so we can reuse it in other projects.
Open the last project you worked on in Chapter 2, DataAccessSample06.xlsm, and then
open the VBE. In the Project Explorer, right-click the cExcelUtils class icon and choose Export
File from the shortcut menu, as shown in Figure 4-5.
Figure 4-5. Exporting a module
Choose your location and save the *.cls file. Once that??™s done, you can close the
DataAccessSample06.xlsm workbook. Right-click anywhere in the Project Explorer in the
UserForm.xlsm project, and choose Import File, as shown in Figure 4-6. Navigate to where
you just saved the cExcelUtils.
Pages:
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158