ปัญหา DAO recordset
กระทู้เก่าบอร์ด อ.Yeadram

 974   5
URL.หัวข้อ / URL
ปัญหา DAO recordset

โค้ด Save
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sql As String
sql = "select * from Personnel "
    Set db = CurrentDb()
    Set rst = db.OpenRecordset(sql, dbOpenDynaset)
      
               rst.AddNew
               rst.Fields("Birthday") = Me.txtBirthday
                   .............
                   ...............
                   ...............
               rst .Update
               rst .close
        ........
       ...........
ปัญหา: ถ้าใส่ข้อมูลวันที่ txtbirthday กดบันทึก ได้ไม่มีปัญหา แต่ถ้าไม่ใส่ข้อมูลวันที่กดบันทึก จะมีปัญหา โปรแกรมจะ debug ไปที่ rst.fields("Birthday")ตลอด
ไม่รู้ว่าเกิดจากสาเหตุอะไร?

5 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R18622
If Me.txtBirthday & "" <> "" Then
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim sql As String
    sql = "select * from Personnel "
        Set db = CurrentDb()
        Set rst = db.OpenRecordset(sql, dbOpenDynaset)
       
               rst.AddNew
               rst.Fields("Birthday") = Me.txtBirthday
                   .............
                   ...............
                   ...............
               rst .Update
               rst .close
        ........
       ...........
End If
2 @R18624
ขอบคุณครับ โค้อข้างบนตรวจสอบtxtbirthdayก่อนบันทึก แต่ในกรณีของผมเจ้าหน้าที่บันทึกไปแล้ว ดึงข้อมูลขี้นมาใหม่เพื่อแก้ไขข้อมูลอื่นแต่ไม่ใช่ข้อมูลวันเกิด(วันเกิดยังว่าง)เวลาบันทึกจะเกิดปัญหาดังกล่าว
3 @R18625
งั้นใช้คำสั่ง IsNull แทนครับ

If isNull(Me.txtBirthday) Then
4 @R18626
ต้องการตรวจสอบค่าว่างบรรทัดไหนก็ใส่ตรงนั้น

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim sql As String
    sql = "select * from Personnel "
        Set db = CurrentDb()
        Set rst = db.OpenRecordset(sql, dbOpenDynaset)

               rst.AddNew
If Me.txtBirthday & "" <> "" Then ' ถ้า txtBirthday มีข้อมูลถึงใส่ลงในฟิลด์
               rst.Fields("Birthday") = Me.txtBirthday
End If
                   .............
                   ...............
                   ...............
               rst .Update
               rst .close
        ........
       ...........
5 @R18627
โค้ดเดิมทดสอบกับเครื่องอื่นผ่านได้ไม่มีปัญหา แต่บางเครื่องก็มีปัญหา ได้แก้ปัญหาตามคำแนะนำ ขอบคุณครับทุกๆท่านที่ให้คำแนะนำ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.2690s