我想在Form_KeyPress的控制窗体中的文本框只能输入数字,为何下面这样,不会执行到?
键盘输入的时候不会调到Form_KeyPress???Private Sub Form_KeyPress(Keyascii as integer)
select case Keyascii
case 13case else
 If left(me.ActiveControl.Name,3)="Txt" then
     '只能输入数字
 End IfEnd Sub

解决方案 »

  1.   

    Private Sub Form_KeyPress(KeyAscii As Integer)
     If Left(Me.ActiveControl.Name, 3) = "txt" Then
         If KeyAscii > 60 Then KeyAscii = 0
     End If
    End SubPrivate Sub Form_Load()
    Me.KeyPreview = True
    End Sub
      

  2.   

    控制文本框的输入你要把代码写到文本框对象的keypress事件里去
      

  3.   

    文本框的话,你可以使用控件数组,这样写一个文本框的 KEYPRESS 就可以了
      

  4.   

    Me.KeyPreview = True这样行了可碰到另外一个问题
    GotFocus和LostFocus又如何控制呢,我没有用控件数组