Search all queries for criteria
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 256   1
URL.หัวข้อ / URL
Search all queries for criteria

ถามไว้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_2000&Number=169164&page=0&view=collapsed&sb=5&o=7&fpart=1&vc=1&PHPSESSID= 
 
เขามี Queries จำนวนมหาศาล เขาต้องการค้นหา Criteria บางตัว และเพื่อเปลี่ยน 
 
ผมเลยให้ฟังก์ชันนี้เขาไปครับ 
 
Function fFindAndReplace(strFind As String, strReplace As String) 
 
Dim dbs As Database, qdf As QueryDef 
Dim strSQL As String 
 
Set dbs = CurrentDb 
 
For Each qdf In dbs.QueryDefs 
    strSQL = qdf.SQL 
    If InStr(strSQL, strFind) > 0 Then 
        If MsgBox(qdf.Name & vbCrLf & vbCrLf & strSQL, vbOKCancel, "Change this?") = vbOK Then 
            strSQL = Replace(strSQL, strFind, strReplace) 
            qdf.SQL = strSQL 
        End If 
    End If 
Next 
 
dbs.Close 
Set dbs = Nothing 
 
End Function 
 
วิธีการใช้ 
 
? fFindAndReplace("kaeg","What InventoryID to be updated?") 
 
ให้ค้นหาคำว่า kaeg ในทุก Queries ถ้าเจอให้แทนค่าด้วย What InventoryID to be updated?" 
 
การ Hard Code ในส่วนของ Criteria มันจะมีปัญหาอย่างนี้ ถ้าวันใดเราต้องการเปลี่ยนเงื่อนไขดังกล่าว 
ควรจะใช้ Query By Form จะดีกว่า ถึงแม้ว่าถ้าขณะนั้นไม่ได้มีการเปิด Form นั้นไว้ มันก็จะถามให้เราใส่เงื่อนไขเอง 
 
 

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

1 @R06652
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0466s