ตัวอย่างการค้นหาข้อมูลโดยให้ user คียคำที่ต้องการลงไปในช่องต่างๆในฟอร์ม
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 529   8
URL.หัวข้อ / URL
ตัวอย่างการค้นหาข้อมูลโดยให้ user คียคำที่ต้องการลงไปในช่องต่างๆในฟอร์ม

วันนี้ผมไปอ่านคำถาม แล้วเขาให้ตัวอย่างมาให้ศึกษาดูด้วย 
เป็นตัวอย่างการค้นหาข้อมูล โดยให้ user กรอกสิ่งที่ต้องการจะค้นหาในช่องทำกำหนดไว้ใน Main Form แล้วให้แสดงผลลัพธ์ใน Subform ลองไปเอามาศึกษาดูได้นะครับที่ 
 
http://www.utteraccess.com/forums/uploads/109364-QBFUsingANDAnd3SearchFieldsVer97.zip 
 
จัดทำโดย Jack Cowley เป็นไฟล์ของ Access97  
 
ถ้าใครต้องการที่จะเข้าไปอ่านกระทู้ที่ให้ตัวอย่างนี้มา ให้ไปดูได้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=109343&page=0&view=collapsed&sb=5&o=7&fpart=1 
 
ผมไปเอามาศึกษาแล้วครับ และได้ปรับปรุงโค้ดของเขาด้วย เพื่อให้มีประสิทธิภาพยิ่งขึ้น โดยไม่ต้องลบ Query เป้าหมายทุกครั้งที่จะค้นหา เพราะจะทำให้จำนวน object ที่จะสร้างใหม่ได้ในไฟล์ db หนึ่งตัวเกินจำนวนที่กำหนดได้ 
 
ผมปรับปรุงของเขาดังนี้ครับ 
 
Private Sub Command8_Click() 
Dim db As DAO.Database 
Dim QD As DAO.QueryDef 
Dim where As Variant 
 
Set db = CurrentDb() 
'Delete the existing dynamic query; trap the error if the query does not exist. 
'On Error Resume Next 
'db.QueryDefs.Delete ("Dynamic_Query") 
'On Error GoTo 0 
 
where = Null 
 
If Left(Me![Organisation], 1) = "*" Or Right(Me![Organisation], 1) = "*" Then 
    where = where & " AND [Organisation] Like '" + Me![Organisation] + "'" 
Else 
    where = where & " AND [Organisation]='" + Me![Organisation] + "'" 
End If 
 
If Left(Me![Service], 1) = "*" Or Right(Me![Service], 1) = "*" Then 
    where = where & " AND [Service] Like '" + Me![Service] + "'" 
Else 
    where = where & " AND [Service]='" + Me![Service] + "'" 
End If 
 
If Left(Me![Other], 1) = "*" Or Right(Me![Other], 1) = "*" Then 
    where = where & " AND [Other] Like '" + Me![Other] + "'" 
Else 
    where = where & " AND [Other]='" + Me![Other] + "'" 
End If 
 
'Set QD = db.CreateQueryDef("Dynamic_Query", _ 
      "Select * from connex " & (" where " + Mid(where, 6) & ";")) 
 
Set QD = db.QueryDefs("Dynamic_Query") 
QD.SQL = "Select * from connex " & (" where " + Mid(where, 6) & ";") 
 
'DoCmd.OpenQuery "Dynamic_Query" 
Me.MySubform.Form.RecordSource = "Dynamic_Query" 
 
End Sub 
 
ลองดูครับว่า ผมแก้ตรงไหน

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

1 @R00596
หรือจะไปอ่านบทความเต็มของ Microsoft ก็ได้ครับที่ http://support.microsoft.com/default.aspx?scid=kb;en-us;q136062
2 @R01713
ผมขออนุญาตครับ ผมไปที่ Link ไม่ได้เสียนะครับ ไม่ทราบว่าตัวอย่างมีหรือไม่ ขอความกรุณาตอบด้วย
3 @R01714
ให้เข้าไปที่กระทู้ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=109343&page=0&view=collapsed&sb=5&o=7&fpart=1 ก่อน แล้วค่อย d/l ไฟล์ที่เขาแนบไว้ครับ
4 @R01792
อ.สุภาพครับผมได้เข้าไปที่ Link ตามที่ อ.แนะนำ แล้วก็ไม่สามารถ D/L ได้ พอคลิกไฟล์ที่ Attachment ก็จะให้ Login ...ไม่ทราบ อ.สุภาพมีเทคนิคที่จะแนะนำหรือเปล่าครับ สำหรับการ D/L ไฟล์นี้ครับ..
5 @R01795
งั้นผมไปเอามาไว้ให้ที่นี่เลยแล้วกันครับ
6 @R01798
แซงคิว หลายเด้อออ..!
7 @R01843
I has been download successful. but still got some error as I attached image file. Would you please recommend What I did something wrong? Any reply would be appreciate. P.S. Sorry to type in Thai, my thai pc doesn't work.
8 @R01844
คิดว่าปัญหาอยู่ที่ DAO 3.6 ครับ ให้ไปที่เมนู Tools>References>แล้วมองหา Microsoft DAO 3.6 Object Library แล้วคลิกเลือก แล้วลอง Compile ใหม่ ก็จะเล่นได้เองครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0607s