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

Jim DeMarco

"Pro Excel 2007 VBA"

Value = ""
Me.txtState.Value = ""
Me.chkHeard.Value = False
Me.chkInterested.Value = False
Me.chkFollowup.Value = False
End Sub
CHAPTER 4 n USERFORMS 144
Our form has three command buttons: one to save the data entered (Save), one to clear
the form and add a new record (New), and one to cancel the data entry operation and close
the form without saving the data (Cancel).
The Save button should perform a few functions for us:
??? Sending the data to the cCustSurvey class
??? Validating the data and returning a message if the data is not valid
??? Saving the data if valid and returning a message if the save is successful
??? Cleaning up the form after the save and resetting the saved flag
Here is the code for the Save button:
Private Sub cmdSave_Click()
With m_oCustSurvey
.State = txtState.Text
.PhoneNumber = txtPhone.Text
.HeardOfProduct = chkHeard.Value
.WantsProduct = chkInterested.Value
.Followup = chkFollowup.Value
End With
If Not m_oCustSurvey.ValidateData Then
MsgBox "State and Phone Number required", vbOKOnly, "Cannot Save"
Exit Sub
Else
m_blnSaved = m_oCustSurvey.Save
End If
DoAfterSave m_blnSaved
End Sub
The first section of the code is sending the values to the class. In the real world, our class
would perform some input validations (such as validating that we entered a phone number
using the correct format).
With m_oCustSurvey
.State = txtState.Text
.PhoneNumber = txtPhone.Text
.HeardOfProduct = chkHeard.Value
.WantsProduct = chkInterested.


Pages:
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165