據我知道你想運行查詢保存在表中的多個查詢。一些查詢取決於父查詢。
僞邏輯:
- 運行和執行父查詢
- 如果結果存在檢索值
- 開始循環,直到父查詢具有值
- 檢索/構建子查詢
- 執行子查詢
- 結束循環
一些僞代碼:
dim MyDb as Dao.Database
dim myRs as Dao.Recordset
set mydb = currentdb
dim SQL_PARENT as string
sql_parent = "" ' Retrieve your parent query here
sql_parent = vba.replace(sql_parent, "searchkey", "replace_key") ' Replace keys
' or if you have the keys in a table then use the dlookup() function to replace keys
set myrs = mydb.openRecordSet(sql_parent)
'do error trapping here
dim iResult = nz(myrs("ResultField"),"")
'follow the parent query operation
'construct the sub queries
dim RS_SUB as DAo.Recordset
dim SQL_SUB as string
dim I as integer
for i = 1 to total of your query collection
sql_sub = query_collection(i)
sql_sub = vba.replace(sql_sub,"searchkey",iResult)
set rs_sub = mydb.openrecordset(sql_sub)
next i
注:這只是一個僞答案,幫助您瞭解的可能性您的方案。