ขอcode การค้นหาข้อมูลทีละหลายฟิลด์
กระทู้เก่าบอร์ด อ.Yeadram

 1,209   7
URL.หัวข้อ / URL
ขอcode การค้นหาข้อมูลทีละหลายฟิลด์

ตารางT1 มีพิลด์ TA1 เก็บID TA2 เก็บชื่อ TA3 เก็บวันเดือนปีเกิด TA4 เก็บเพศ TA10 เก็บชื่อหมู่บ้าน
จากตัวอย่างในรูป มีTxetBox1 กรอกพศ.เกิด TextBox2 กรอกเพศ TexBox3 กรอกชื่อหมู่บ้าน มีปุ่มA เมื่อคลิกปุ่มA จะกรองข้อมูลจากตารางข้างล่างที่เห็นในรูป
คำถาม หนูจะเขียนCode ที่ปุ่มอย่างไรคะ

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

1 @R16999
ส่งรูปไปที่ accboard_gmail@gmail.com ชื่อเมล์ถูกต้องใหมคะ
2 @R17010
accboard@gmail.com
3 @R17011
ขอบคุณค่ะ หนูส่งรูปแนบคำถามไปตามเมล์ใหม่ที่ให้มาแล้วค่ะช่วยดูให้หน่อยนะคะ
4 @R17012
ไม่มีอะไรแนบมาเลย
5 @R17014
ส่งมาให้ใหม่แล้วค่ะเป็นZipค่ะ
ขอบคุณค่ะ
6 @R17018
Option Compare Database
Option Explicit

dim rs as dao.recordset
dim db as dao.database

Private Sub Form_Open(Cancel As Integer)
       set db = currentdb
End Sub

Private Sub A_Click( )
       dim where as string

       if trim(nz(me.TA3,"")) <> "" then where = " (TA3 like ""%" & me.TA3 & "%"") "   
       if trim(nz(me.TA4,"")) <> "" then where = iif(where = "","",where & " and ") & " (TA4 like ""%" & me.TA4 & "%"") "
       if trim(nz(me.TA10,"")) <> "" then where = iif(where = "","",where & " and ") & " (TA10 like ""%" & me.TA10 & "%"") "

      if where = "" then
          msgbox "ป้อนเงื่อนไขค้นหาด้วย"
          exit sub
      end if

       set rs = db.OpenRecordset("select * from T1 where " & where & " order by TA1")
       set me.recordset = rs
End Sub

Private Sub Form_Close()
     on error resume next
      rs.close: set rs = nothing
      db.close: set db = nothing
End Sub


แต่ถ้า TA3 เก็บเป็นฟิลด์ date/time ให้เปลี่ยนเงื่อนไขบรรทัดของ TA3 เป็น
if trim(nz(me.TA3,"")) <> "" then where = " (year(TA3) = " & me.TA3 & ") "
7 @R17021
ขอบคุณค่ะ
เดี๋ยวจะลองเอาไปทำดูค่ะได้ผลอย่างไรจะแจ้งให้ทราบค่ะ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.3684s