我想通過將我的SQL代碼轉換成String
然後執行重新查詢函數來查詢我的子表單。問題是,我無法將下面的SQL代碼轉換爲.RecordSource
可以評估的合適字符串。Requery子表
這是我原來的SQL代碼:
SELECT tbl_Records.Inst_ID, [tbl_Instruments].[Type] & "-" & [tbl_Instruments].[Item] AS [Tool ID], tbl_Records.Cal_Date AS Cal_Date, tbl_Cal_By.Name_ABBR AS Cal_By, tbl_Records.As_Received, tbl_Records.Result, DateAdd("d",[tbl_Instruments]![Lead_Time],DateAdd("m",[qry_CofC]![Calibration Freq],[tbl_Records]![Cal_date])) AS Next_Due, DateDiff("d",Date(),DateAdd("d",[tbl_Instruments]![Lead_Time],DateAdd("m",[qry_CofC]![Calibration Freq],[tbl_Records]![Cal_date]))) AS Due
FROM (tbl_Cal_By RIGHT JOIN (tbl_Instruments INNER JOIN tbl_Records ON tbl_Instruments.ID = tbl_Records.Inst_ID) ON tbl_Cal_By.ID = tbl_Records.BY) INNER JOIN qry_CofC ON tbl_Instruments.ID = qry_CofC.ID
WHERE (((Exists (SELECT 1 FROM tbl_Records t
WHERE t.Inst_ID = tbl_Instruments.ID
AND t.Cal_date > tbl_Records.Cal_Date))=False));
這就是我如何重新查詢:
Dim SQL As String
SQL = "ABOVE ORIGINAL SQL CODE"
subform_Records.Form.RecordSource = SQL
subform_Records.Form.Requery
您的sql代碼在保存的查詢中工作嗎?如果是這樣,你可以引用你的記錄來源保存的查詢,並使用me.subformname.requery – SunRay