家庭住址不能输入特殊字符
1. Private Sub txtAddress_KeyPress(KeyAscii As Integer) 2. Dim cTemp As String 3. cTemp = "`~!@#$%^&*()-=_+[]{};:'\|<>/?.‘“”’、,。——+()《》?,~·……¥!:;【】" & """ '禁止输入特殊的字符" 4. If InStr(1, cTemp, Chr(KeyAscii)) <> 0 Then 5. KeyAscii = 0 6. End If 7. End Sub
姓名只能输入汉字
1. Private Sub txtName_keypress(KeyAscii As Integer) 2. If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then 3. Else 4. KeyAscii = 0 5. MsgBox "请输入汉字!", vbOKOnly + vbExclamation, "提示" 6. txtName.SetFocus 7. End If 8. End Sub
班号只能输入数字(无提示)
1. Private Sub comboclassno_KeyPress(KeyAscii As Integer) 2. If KeyAscii < 7 Or KeyAscii > 9 And KeyAscii < 48 Or KeyAscii > 57 Then 3. KeyAscii = 0 4. End If 5. End Sub
学号文本框中只能输入数字(无提示)
1. Private Sub txtSID_keypress(KeyAscii As Integer) 2. Select Case KeyAscii 3. Case 48 To 57 4. Case 8 5. Case Else 6. KeyAscii = 0 7. MsgBox "请输入数字", vbOKOnly + vbExclamation, "提示" 8. txtSID.Text = "" 9. End Select 10. End Sub
入学日期不能大于出生日期的代码
1. Private Sub DTPBorndate_change() 2. If DTPBornDate.Value >= DTPRudate.Value Then 3. MsgBox "入学日期大于出生日期,请重新选择!", vbOKOnly + vbExclamation, "提示" 4. DTPBornDate.SetFocus 5. End If 6. End Sub 7. 8. Private Sub DTPRudate_change() 9. If DTPRudate.Value <= DTPBornDate.Value Then 10. MsgBox "入学日期大于出生日期,请重新选择!", vbOKOnly + vbExclamation, "提示" 11. DTPRudate.SetFocus 12. End If 13. End Sub