Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then SendKeys "{Tab}"
End Sub

解决方案 »

  1.   

    当然,应该首先验证数据的合法性,然后sendkeys,
      

  2.   

    验证数据的合法性放到Validate里更好
      

  3.   

    验证数据的合法性放到Validate里更好 
    否则通过鼠标、或者按tab、或者通过代码转移焦点怎么办?
      

  4.   

    一种通用的方法:
    设置窗体keypreview=true,在窗体的keypress中拦截enter。
    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
      If TypeName(Me.ActiveControl) = "TextBox" Then
        KeyAscii = 0
        SendKeys "{tab}"
      End If
    End If
    End Sub
      

  5.   

    private sub Text1_keypress(index as integer,keyascii as integer)
    if keyascii=13 and 条件 then text1(index+1).setFocus
    end sub