I have a select query in Access VBA. This query is a record source for a report. This report is a Sub Report of a Sub Report. I need the query to produce a string when there is no record exist for any particular search. Therefore, this subreport could be shown in the main report
Query Name: Qry_To_Be_Imoroved.
SELECT To_Be_Improved.To_Be_Improved, To_Be_Improved.Record_ID, To_Be_Improved.ID
FROM To_Be_Improved
WHERE (((To_Be_Improved.Record_ID)=[Reports]![Incident_Report_Updated]![Record_ID]));
How can I amend this to add a string to "To_Be_Improved" column when there is no record for a query.
答案 0 :(得分:0)
不是试图让查询给出没有记录的结果,而是可以对结果进行一些VBA测试:
Set myRecordset = db.OpenRecordset(mySQLquery)
If myRecordset.RecordCount = 0 Then
MsgBox "No records for this selection"
End If
在不知道数据库的细节的情况下,也可能有一个摘要查询来计算每个实例的记录数,然后根据该查询使用SWITCH进行另一个查询以提供文本输出:
Switch(numRecords=0,"To Be Improved",numRecords>0,"We good") AS To_Be_Improved