ตรวจดูว่ามีการใช้ Query ใน Form หรือ Report ไหนบ้าง
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 244   1
URL.หัวข้อ / URL
ตรวจดูว่ามีการใช้ Query ใน Form หรือ Report ไหนบ้าง

มีคนถามไว้ที่เก่าแหล่ะครับ คือ
http://www.quicktechusa.com/msgboard/wwwboard.pl?read=17132

เนื้อหาของคำถามมีดังนี้


I need to know if there is a way to search for objects within a database. For example, I would like to know where and when QueryA is used, meaning from which forms and/or reports. I hope I am making sense. Thanks for all help!

Estee


แปลเป็นไทยก็คือหัวข้อของกระทู้นี้แหล่ะครับ

ผมได้ลองทำดู และได้ตอบโค้ดในการตรวจดังกล่าว ดังนี้

Sub QueriesUsed()
Dim dbs As Database, qdf As QueryDef, doc As Document
Dim strQry As String, strFrm As String
Set dbs = CurrentDb
For Each qdf In dbs.QueryDefs
strQry = qdf.Name
If Left(strQry, 3) <> "~sq" Then
'Debug.Print strQry
With dbs.Containers!Forms
For Each doc In .Documents
strFrm = doc.Name
'Debug.Print strFrm
DoCmd.OpenForm strFrm, , , , , acHidden
If Forms(strFrm).RecordSource = strQry Then
Debug.Print "Yes Forms" & ", " & strFrm & " --> " & strQry
End If
DoCmd.Close acForm, strFrm
Next doc
End With
With dbs.Containers!Reports
For Each doc In .Documents
strFrm = doc.Name
'Debug.Print strFrm
DoCmd.OpenReport strFrm, acViewDesign
If Reports(strFrm).RecordSource = strQry Then
Debug.Print "Yes Reports" & ", " & strFrm & " --> " & strQry
End If
DoCmd.Close acReport, strFrm
Next doc
End With
End If
Next qdf
dbs.Close
End Sub



ข้อระวัง
query บางตัวยังใช้ในการเขียนโค้ดบางอย่างด้วย จึงต้องตรวจสอบให้ดี ก่อนที่จะตัดสินใจลบ query ใดๆ ทิ้งครับ

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

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