Try this:
Code:
Option Compare Database
Option Explicit
Private Sub Command8_Click()
Dim nominal As Single
Dim plus As Double
Dim minus As Double
Dim dimension As Double
Dim hi As Double
Dim lo As Double
nominal = RRound(txtNominal.Value, 4)
plus = RRound(txtPlus.Value, 4)
minus = RRound(txtMinus.Value, 4)
dimension = RRound(txtDimension, 4)
hi = RRound(nominal + plus, 4)
lo = RRound(nominal - minus, 4)
txtDimension.BackColor = vbWhite
If dimension > (hi) Then
txtDimension.BackColor = vbYellow
MsgBox "The given dimension is over tolerance"
MsgBox "Tolerance high = " & hi & vbNewLine & "Dimension = " & dimension
ElseIf dimension < (lo) Then
txtDimension.BackColor = vbYellow
MsgBox "The given dimension is below tolerance"
MsgBox "Tolerance high = " & lo & vbNewLine & "Dimension = " & dimension
Exit Sub
End If
End Sub
Function RRound(FieldValue As Variant, Optional intPos As Integer = 0) As Variant
'--------------------------------------------------
' Function RRound() rounds value to designated decimal position.
' If argument does not contain data, RRound returns null.
' Use because intrinsic Round uses even/odd (banker's) rounding.
' Also, Format and FormatNumber functions don't use even/odd but
' generate a string result which is often inconvenient.
'--------------------------------------------------
Dim strZeros As String
Dim i As Integer
If intPos = 0 Then
strZeros = 0
Else
For i = 1 To intPos
strZeros = strZeros & 0
Next
strZeros = "0." & strZeros
End If
RRound = IIf(Not IsNull(FieldValue), Val(Format(FieldValue, strZeros)), Null)
End Function