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

Jim DeMarco

"Pro Excel 2007 VBA"

Value
.Followup = chkFollowup.Value
End With
The second section of the code is calling the m_oCustSurvey.ValidateData method and
displaying a message if both text fields do not contain data. If the data is present, the
m_oCustSurvey.Save method is called.
CHAPTER 4 n USERFORMS 145
Finally, we??™re calling a function called DoAfterSave to perform our cleanup. We??™re passing
in our success flag so that this method will be the one calling out any messages to the user.
Private Sub DoAfterSave(success As Boolean)
If success Then
ClearForm
lblID.Caption = m_oCustSurvey.GetNextID
MsgBox "Record Saved"
Else
MsgBox "Could not save record"
End If
m_blnSaved = False 'resetting flag
End Sub
Our cleanup code clears the form, gets the next available ID number from the database,
and sends the user a success (or failure) message.
The New command button has the job of clearing the formand getting a new ID from the
database. Before it does that, it must check the text fields to see if they have any data entered.
The code for the New command button follows:
Private Sub cmdNew_Click()
'sets form up for a new record
Dim iAnswer As Integer
'check that current record is saved (if any)
If Not m_blnSaved Then 'see if any text data is entered that is not saved
If (Len(Me.txtPhone.Value & "") + Len(Me.txtState.Value & "")) <> 0 Then
iAnswer = MsgBox("There is unsaved data. Do you want to continue?", _
vbYesNo, "Unsaved Data")
If iAnswer = vbYes Then
ClearForm
End If
Else
ClearForm
End If
End If
End Sub
We??™re using the following line of code to determine whether we have data in one of our
two text input fields:
If (Len(Me.


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