我在互联网上找到了这些代码并将它们放在表格上。它似乎很好地工作除了一件事:它一直告诉我“你已经放错了表达式...”如果我不进行计算(默认情况下,该字段是从其他2个字段自动计算的)。请有人告诉我代码有什么问题?感谢
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
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 And Shift = 0 Then
If Me.ActiveControl.ControlType = acTextBox Then
If Me.ActiveControl.DecimalPlaces <> 255 Then
varNewValue = Eval(Me.ActiveControl.Text)
Me.ActiveControl.Text = varNewValue
KeyCode = 9
End If
End If
End If
Exit Sub
SkipOut: strErr = Error(Err)
On Error Resume Next
KeyCode = 9
MsgBox Left(strErr, InStr(strErr & "@", "@") - 1)
Exit Sub
End Sub