转换/过滤用户输入的文本时访问奇怪

时间:2018-02-27 21:07:41

标签: ms-access access-vba ms-access-2010

有人可以解释为什么会有效:

Private Sub PartNum_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 47 To 57
            KeyAscii = KeyAscii
        Case 97 To 122
            KeyAscii = KeyAscii - 32
        Case Else
            KeyAscii = 0
    End Select
End Sub

但为什么这不起作用:

Function gUC(ByVal gKey As Integer) As Integer
    Select Case gKey
        Case 47 To 57
            gKey = gKey
        Case 97 To 122
            gKey = gKey - 32
        Case Else
            gKey = 0
    End Select
End Function

Private Sub PartNum_KeyPress(KeyAscii As Integer)
    KeyAscii = gUC(KeyAscii)
End Sub

我的表单上有多个字段,我希望像这样过滤,而只是调用一个函数而不是为每个字段重写代码

1 个答案:

答案 0 :(得分:0)

我认为你没有正确回报价值。

Function gUC(ByVal gKey As Integer) As Integer
    Select Case gKey
        Case 47 To 57
            gUC= gKey
        Case 97 To 122
            gUC= gKey - 32
        Case Else
            gUC= 0
    End Select
End Function