如何使用for循环创建多个SUB?

时间:2014-10-09 00:23:38

标签: vba ms-access textbox access-vba

大家。我创建了一个包含一些文本框的表单。我还创建了它的事件(选择了多个文本框并设置了它的On Key Up事件)。但是现在,我有一个问题。我希望所有事件都执行相同的功能(判断键盘值。如果它不在范围内,则弹出一个msgbox)

Sub call_msgbox(column)
    Dim b As Integer
    b = CInt(column.Text)
    If b > 500 Then
        MsgBox "Higer than 500"
    ElseIf b < 330 And b > 100 Then
        MsgBox "Lower than 330"
    End If
End Sub
Private Sub A1_Z1_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode > 95 And KeyCode < 106 Then
    call_msgbox A1_Z1
    ElseIf KeyCode > 47 And KeyCode < 58 Then
    call_msgbox A1_Z1
    End If
End Sub
Private Sub A1_Z2_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode > 95 And KeyCode < 106 Then
    call_msgbox A1_Z2
    ElseIf KeyCode > 47 And KeyCode < 58 Then
    call_msgbox A1_Z2
    End If
End Sub
Private Sub A1_Z3_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode > 95 And KeyCode < 106 Then
    call_msgbox A1_Z3
    ElseIf KeyCode > 47 And KeyCode < 58 Then
    call_msgbox A1_Z3
    End If
End Sub

依旧...... 但它太多了。我不想复制和粘贴。有什么建议吗? http://i.stack.imgur.com/JixKC.png

0 个答案:

没有答案