电大 VB作业,请VB高手帮忙!!!

要求:用户在第1个文本框输入信息后,按回车键,程序能够自动将焦点转换到下一个文本框,使用户不必使用鼠标就可以继续在下一个文本框输入信息。

Private Sub Command1_Click()
MsgBox "根据你输入的值,拼写SQL语句如下:" & vbCrLf & _
"INSERT INTO 学生表(学号,姓名,年龄)" & _
vbCrLf & "VALUES('" & Text1 & "','" & Text2 & "','" & Text3 & "')"

End Sub

Private Sub Command2_Click()
End

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Text2.SetFocus

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
Text3.SetFocus

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
Command1.SetFocus
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-06
假设第一个文本框叫 Text1,第二个叫Text2,现加入如下代码:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0: Text2.SetFocus
End Sub

其中 KeyAscii = 0 的作用是屏蔽按回车键产生的“叮”声。
第2个回答  2012-11-06
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
第3个回答  2012-11-06
百度 :vb 回车转Tab
相似回答