I found this calculator and wanted to share it with you.
I found the original code at this location:
http://it.toolbox.com/wiki/index.php/Add_a..._Access_TextBox
I have cleaned it up... I Just put the text on the different lines so that Access could read it and I added the Enter function to use the enter key to do the calculation.
Code:
Private Sub Qty_KeyDown(KeyCode As Integer, Shift As Integer)
'This is a sample calculator that works within your textbox fields.
'r.l. hane 2006.01.25.
'To use this little calculator, set the form's KeyPreview property to
'Yes and paste this handler into the form's OnKeyDown code.
'This keydown handler responds to the "=" key. If the '=' key
'is pressed in a textbox field that has a DecimalPlaces
'property other than "auto", it attempts to use the Eval
'function to evaluate the math formula typed there. If
'successful it replaces the math formula with the value.
'For example, If you type '2+3*5' into a numeric textbox and
'press '='. The value '17' will be put in it's place. Notice
'that Eval correctly respects the order of operation rules.
'Since it will evaluate any expression, even ones containing
'VBA functions, keep the app in the sandbox or alter it to
'ignore text containing parenthesis characters.
Dim varNewValue As Variant
Dim strErr As String
On Error GoTo SkipOut
' to use the '=' use this line
'If KeyCode = 187 And Shift = 0 Then
'To use the Enter Key (my favorite) use this line
If KeyCode = 13 Then
If Me.ActiveControl.ControlType = acTextBox Then
If Me.ActiveControl.DecimalPlaces <> 255 Then
varNewValue = Eval(Me.ActiveControl.Text)
Me.ActiveControl.Text = varNewValue
KeyCode = 0
End If
End If
End If
Exit Sub
SkipOut: strErr = Error(Err)
On Error Resume Next
KeyCode = 0
MsgBox Left(strErr, InStr(strErr & "@", "@") - 1)
Exit Sub
End Sub