restr = "select * from T_information where F_id='" & Trim(Txt_info.Text) & "'and F_makelistdate=" & Format(DTP_makelistdate.Value, "YYYY-MM") & ""
If Not cn.Execute(restr).EOF Then
    MsgBox "已经有相同制单日期和编号,请问是否进行覆盖?", vbOKCancel + vbExclamation +     vbInformation, "提示"
    Txt_info.Text = ""
    Txt_info.SetFocus
   Exit Sub
End If
 这样写是不是日期写的有问题?

解决方案 »

  1.   

    '如果数据库为ACCESS:
    restr = "select * from T_information where F_id='" & Trim(Txt_info.Text) & "'and 
    F_makelistdate=# " & Format(DTP_makelistdate.Value, "YYYY-MM") & "# "'如果数据库为SQL:
    restr = "select * from T_information where F_id='" & Trim(Txt_info.Text) & "'and 
    F_makelistdate='" & Format(DTP_makelistdate.Value, "YYYY-MM") & "'"
      

  2.   

    单引号和and之间加一个空格restr = "select * from T_information where F_id='" & Trim(Txt_info.Text) & "' and F_makelistdate=" & Format(DTP_makelistdate.Value, "YYYY-MM")