Private Sub cmdUpdate_Click()
 Dim intStatus As Integer
 intStatus = 1
 For Each Control In Form1
     If TypeOf Control Is TextBox Then
        If Trim(Control.Text) = " " Then
        MsgBox "不能为空!"
     intSbj = 0
     Exit For
        End If
     End If
 Next
If intStatus = 1 Then
      Adodc1.Recordset.Update
      MsgBox "数据已更新!"
 End If
End Sub
以上是一个UPDATE键触发的事件,可是不管文本框是否为空它都会更新数据库,我觉得好象没有逻辑错误吧,哪位大侠指点一下!!

解决方案 »

  1.   

    Private Sub cmdUpdate_Click()
     Dim intStatus As Integer
     intStatus = 1
     For Each Control In Form1
         If TypeOf Control Is TextBox Then
            If Trim(Control.Text) = "" Then
               MsgBox "不能为空!"
               intStatus = 0
               Exit For
            End If
         End If
     Next
    If intStatus = 1 Then
          Adodc1.Recordset.Update
          MsgBox "数据已更新!"
     End If
    End Sub
      

  2.   

    楼上的高见。主要是控制变量没有赋值,写成了另一个变量intSbj
      

  3.   

    楼上的老兄,不对啊,那个intSbj是我打错了,后来改好,可是按你的改后,不为空也会提示为空啊怪怪
      

  4.   

    加上控件的名字,看看有什么问题.MsgBox Control.Name & "不能为空!"
      

  5.   

    可能是你到某一个text设定了长度的问题不?
    我只是猜想,到现在用了VB个把月了,我还是不习惯用它来做数据库界面,
    所以具体的也不大清楚,只能提个猜想了,因为我碰到过text设定了长度而判断不了的情况。
    要不就采用一个中间变量。
      

  6.   

    用 Cooly(☆回答问题不要分儿☆)的没错
    我试过了
    不会出现你说的问题