Private Sub Command2_Click()
   Data6.DatabaseName = App.Path & "\dbo"
   Data6.RecordSource = "select * from hyxx"
   If Data6.Recordset("dbo_id") = Text27.text Then
   MsgBox "记录已经存在!", vbCritical
   Else
   Data6.Recordset.AddNew
   Data6.Recordset("dbo_id") = Text27.text  
   Data6.Recordset.Update
   Data6.Recordset.MoveLast
  End If
End Sub
库中已有一个dbo_id号为2,第一次点击command2时不知为什么会先执行ELSE后面的语句,当再一次点击COMMMAND2时不知为什么又执行了IF后面的语句.总是要点两次才判断"记录已经存在"?请高手指点.

解决方案 »

  1.   

    Data6.DatabaseName = App.Path & "\dbo"
       Data6.RecordSource = "select * from hyxx where dbo_id=" &val(Text27.text)
       If not Data6.Recordset.eof Then
       MsgBox "记录已经存在!", vbCritical
       Else
       Data6.Recordset.AddNew
       Data6.Recordset("dbo_id") = Text27.text  
       Data6.Recordset.Update
       Data6.Recordset.MoveLast
      End If
      

  2.   

    Data6.RecordSource = "select * from hyxx where dbo_id=" &val(Text27.text)
    在这句中再加一个text28.text的条件,怎么加?请高手指点
      

  3.   

    Data6.RecordSource = "select * from hyxx where dbo_id=" &val(Text27.text) or dbo_id="&val(Text28.text) 另:建议楼主确认字段dbo_id的类型,是字符型还是数值型?如果是字符型别忘了加单引号又:SQL语法很重要
      

  4.   

    Private Sub Command2_Click()
      Data6.DatabaseName = App.Path & "\dbo"
       Data6.RecordSource = "select * from dbo_hyxx where dbo_hyxx.dbo_id=" & Val(Text27.text) And dbo_hyxx.dbo_db_hymc = " & val(text31.text)"
       Data6.Refresh
       If Not Data6.Recordset.EOF Then
       MsgBox "会议中已有此人!", vbCritical
       Else
       Data6.Recordset.AddNew
       Data6.Recordset("dbo_id") = Text27.text
       Data6.Recordset("dbo_db_hymc") = Text31.text 
      End If
      End Sub 不知为什么一执行总是提示"记录已经存在"?请高手指点.
      

  5.   

    Private Sub Command2_Click()
      Data6.DatabaseName = App.Path & "\dbo"
       Data6.RecordSource = "select * from dbo_hyxx where dbo_hyxx.dbo_id=" & Val(Text27.text) And dbo_hyxx.dbo_db_hymc = " & val(text31.text)"
       Data6.Refresh
       If Not Data6.Recordset.EOF Then
       MsgBox "记录已经存在!", vbCritical
       Else
       Data6.Recordset.AddNew
       Data6.Recordset("dbo_id") = Text27.text
       Data6.Recordset("dbo_db_hymc") = Text31.text 
      End If
      End Sub 不知为什么一执行总是提示"记录已经存在"?请高手指点.