1,只能输入数字
If keyascii = 8 then exit sub
If keyascii <48 or keyascii > 57 then keyascii = 0
2,限制粘贴
If keycode = vbkeyv and shift =vbctrlmask then
Txtpassword. Enabled = false
Clipboard.clear
Txtpassword.enabled = true
End if
3,限制特殊字符,数字,空格,只能输入字母或汉字
Private sub txtcoursename_keypress(keyascii as integer)
If keyascii < 0 or keyascii = 8 or keyascii = 13 then
Elseif not chr(keyascii) like "[a-zA-Z]" then
Keyascii = 0
End if
End sub
4,提示密码剩余次数,密码只可以输入三次,提醒用户
If miCout = 1 Then
MsgBox "您还有两次机会!", 48, "警告"
Exit Sub
End If
If miCout = 2 Then
MsgBox "您还有一次机会!", 48, "警告"
Exit Sub
End If
If miCout = 3 Then
MsgBox "即将关闭程序!", 48, "警告"
Me.Hide
End If
Exit Sub
5,入校日期早于出生日
dim borndate as date
dim getdate as date'定义变量'
borndate = trim(txtborndate.text)
getdate = trim(txtborndate.text)
If getdate<=borndate then'进行比较
MsgBox"入学时间不能早于出生时间,请重新输入",vbOKOnly + vbInformation,"警告" txtRudate.SetFocus
Exit Sub
End If
6,限制字符长度
在属性栏里找到Maxlength更改就好