Hi. Curt.
Could I get someone to help me on the code.
Sure. If the names of the text boxes were txtQtr followed by the relevant
digit, txtTotal was the name of the text box to display the total, and
txtQtr4 was the last text box that you are interested in making sure that the
calculation is made, then you could try the following code:
' * * * * Start Code * * * *
Private Sub txtQtr4_Exit(Cancel As Integer)
On Error GoTo ErrHandler
Dim nTotal As Integer
Dim nAns As Integer
nTotal = (CInt(Nz(Me!txtQtr1.Value, 0))) + (CInt(Nz(Me!txtQtr2.Value,
0))) + _
(CInt(Nz(Me!txtQtr3.Value, 0))) + (CInt(Nz(Me!txtQtr4.Value, 0)))
If (nTotal <> 10) Then
nAns = MsgBox("The total doesn't equal 10. Do you" & vbCrLf & _
"wish to use this value anyway?", vbYesNo, "Total Is Not 10")
If (nAns = vbYes) Then
Me!txtTotal.Value = nTotal
Else
' Do whatever alternative that you want. For example:
Cancel = True ' Focus stays in the current text box.
End If
End If
Exit Sub
ErrHandler:
MsgBox "Error in txtQtr4_Exit( ) in " & vbCrLf & Me.Name & " form." & _
vbCrLf & vbCrLf & "Error #" & _
Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
' * * * * Start Code * * * *
Using the Exit event rather than the Lost Focus event allows the event to be
cancelled.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)
- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that the first and
best answers are often given to those who have a history of rewarding the
contributors who have taken the time to answer questions correctly.