1、关于只能输入汉字和清除键。
Private Sub txt?_KeyPress (KeyPress As Integer)
If KeyAscii >= -20319 And KeyAscii <= -3625 or KeyAscii = 8 then
Else
MsgBox "请输入汉字!", 0 + 48 , "提示"
KeyAscii = 0
txt?.SetFocus
End If
End sub
2、输入框判断字符并作提醒。
Private Sub txt?_Change()
Dim strlen As Long
strlen = Len(txt?.Text)
If strlen > x Then
MsgBox "最多输入x个字", vbOKOnly + vbExclamation, "警告"
txt?.Text = ""
txt?.SetFocus
End If
End Sub
3、输入框只能输入数字。
Private Sub txt?_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Or KeyAscii = 13 Then
Else
If KeyAscii = 32 Then
MsgBox "不能输入空格!", 0 + 48, "警告"
KeyAscii = 0
Else
MsgBox "对不起,课程编号为数字!", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
txt?.Text = ""
txt?.SetFocus
End If
End If
End Sub
4、判断数据库有无记录,若无记录则提示。
Private Sub modifyresultMenu_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
txtSQL = "select * from result_Info "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.RecordCount = 0 Then
MsgBox "当前没有记录,请添加记录"
Exit Sub
End If
frmModifyresult.Show
End Sub
5、文本框输入字符的限制位数。
Text1.MaxLength = x
Private Sub Form_Load()
Dim txtSQL As String
Dim MsgText As String
txtSQL = "select * from student_Info "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If LastData(mrc) Then
Else
mrc.MoveFirst
End If
Call viewData
If Not LastData(mrc) Then
myBookmark = ""
Else
myBookmark = mrc.Bookmark
End If
mcclean = True
End Sub
Public Sub viewData()
If Not (mrc.BOF = False And mrc.EOF = False) Then
MsgBox "数据库目前已经是最后一条数据了!!", vbOKOnly + vbExclamation, "警告"
txtSID.Text = ""
txtName.Text = ""
comboSex.Text = ""
txtBorndate.Text = ""
comboClassNo.Text = ""
txtTel.Text = ""
txtRudate.Text = ""
txtAddress.Text = ""
txtComment.Text = ""
Else
txtSID.Text = mrc.Fields(0)
txtName.Text = mrc.Fields(1)
comboSex.Text = mrc.Fields(2)
txtBorndate.Text = Format(mrc.Fields(3), "yyyy-mm-dd")
comboClassNo.Text = mrc.Fields(4)
txtTel.Text = mrc.Fields(5)
txtRudate.Text = Format(mrc.Fields(6), "yyyy-mm-dd")
txtAddress.Text = mrc.Fields(7)
txtComment.Text = mrc.Fields(8)
End If
End Sub
6、查询成绩未选中check框文本框内容自动清除。
Private Sub Check1_Click(Index As Integer)
If Check1(0).Value = 0 Then
txtSID.Text = ""
Else
End If
If Check1(1).Value = 0 Then
txtName.Text = ""
Else
End If
If Check1(2).Value = 0 Then
txtCourse.Text = ""
Else
End If
End Sub
7、操作数据时数据库中没有数据会报错。
On Error GoTo dateErr
dateErr:
If Err = 3021 Then
MsgBox "没有数据", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
小结
在错误中成长的更快,以上这些就是我在敲学生的时候遇到的部分问题以及解决方案,希望可以帮到大家,站在巨人的肩膀上,这些错误都是你的垫脚石,你会站得越来越高。