1.代碼如下:Private Sub datScore_Validate(Action As Integer, save As Integer)
If (Len(Trim(txtID.Text)) = 0 And Action = vbdataactionupdata) Then
MsgBox "学号不能为空值,请重新输入!", vbCritical + vbOKOnly, "错误"
Action = vbDataActionCancel
ElseIf save And cmdPrevious.Caption <> "确定" Then
save = False
txtID.SetFocus
End If
End Sub
執行後,雖不符合條件者不會加入數據庫當中,但不符合錄入條件的系統不給予提示?2.不能判斷學號是否為空及是否會跟數據庫的字段值有所比較?3.請各位高手指點!呵呵...
If (Len(Trim(txtID.Text)) = 0 And Action = vbdataactionupdata) Then
MsgBox "学号不能为空值,请重新输入!", vbCritical + vbOKOnly, "错误"
Action = vbDataActionCancel
ElseIf save And cmdPrevious.Caption <> "确定" Then
save = False
txtID.SetFocus
End If
End Sub
執行後,雖不符合條件者不會加入數據庫當中,但不符合錄入條件的系統不給予提示?2.不能判斷學號是否為空及是否會跟數據庫的字段值有所比較?3.請各位高手指點!呵呵...
改成:
if trim(txtid.text)=""
if trim(txtid.text)="" then
msgbox "请输入数据!",48,"提示"
txtid.setfocus
exit sub
else
'输入的内容与数据库内容比较
...
...
end if
end sub
//这个没什么区别,不过一般就只要trim(txtid.text)=""这个好了
dim rs as new adodb.recordset
conn.open ... '与数据库建立连接private sub txtid_lostfocus()
if trim(txtid.text)="" then
msgbox "请输入数据!",48,"提示"
txtid.setfocus
exit sub
else
if rs.state=adstateopen then rs.close
rs.open "select * from tablename where 学号='"& trim(txtid.text) &"'",conn,adopenkeyset,adlockreadonly
if rs.recordcount=0 then
msgbox "输入的学号不存在,请重新输入!",48,"提示"
txtid.setfocus
rs.close
exit sub
end if
end if
end sub
这句判断写错了吧?应该把and 改成or吧?意思是其中只要有一个条件满足就要出对话框!!!
如果是and的话必须要txtID.Text=“”并且Action = vbdataactionupdata同时满足的时候才触发!明白了吗?