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.請各位高手指點!呵呵...

解决方案 »

  1.   

    If (Len(Trim(txtID.Text)) = 0
    改成:
    if trim(txtid.text)=""
      

  2.   

    1.請問  if trim(txtid.text)=""與這句If (Len(Trim(txtID.Text)) = 0有啥子區別?2.改後仍不提示?再以請教.
      

  3.   

    private sub txtid_lostfocus()
        if trim(txtid.text)="" then
            msgbox "请输入数据!",48,"提示"
            txtid.setfocus
            exit sub
        else
            '输入的内容与数据库内容比较
            ...
            ...
        end if
    end sub
      

  4.   

    1.謝謝 Leftie(左手,为人民币服务)兄台之回答,但為什麼不用and語句,這樣代碼更簡單些!呵呵..2.請其他高手再予以指教!呵呵...
      

  5.   

    If (Len(Trim(txtID.Text)) = 0 And Action = vbdataactionupdata) Then这句判断写错了吧?应该把and 改成or吧?意思是其中只要有一个条件满足就要出对话框!!!
      

  6.   

    1.請問  if trim(txtid.text)=""與這句If (Len(Trim(txtID.Text)) = 0有啥子區別?
    //这个没什么区别,不过一般就只要trim(txtid.text)=""这个好了
      

  7.   

    1.請問  if trim(txtid.text)=""與這句If (Len(Trim(txtID.Text)) = 0有啥子區別//这两句代码的功能完全一样,都是判断txtID文本框的内容是否为空,不过由于VB内部使用的是UNICODE编码,对字符串的处理内部都需要转换,导致字符串的比较会慢一些;所以用LEN取长度,看是否等于0,这种速度会快一些,推荐使用!!
      

  8.   

    1.偶知道if trim(txtid.text)=""與這句If (Len(Trim(txtID.Text)) 其實就是等價的,跟沒改一樣!2.可偶問題是要解決如何去判斷學號?當用戶輸入錯誤或沒輸時,系統能給予提示!
      

  9.   

    Len(Trim(txtID.Text)) = 0 or Action = vbdataactionupdata
      

  10.   

    dim conn as new adodb.connection
    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
      

  11.   

    If (Len(Trim(txtID.Text)) = 0 And Action = vbdataactionupdata) Then
    这句判断写错了吧?应该把and 改成or吧?意思是其中只要有一个条件满足就要出对话框!!!
    如果是and的话必须要txtID.Text=“”并且Action = vbdataactionupdata同时满足的时候才触发!明白了吗?