cyberman55
Registered User.
- Local time
- Yesterday, 23:56
- Joined
- Sep 22, 2012
- Messages
- 83
Hi again, I read somewhere that it's difficult to pass "null" to a parameterized query when basing the parameter on a form control. I'd like to do that if possible, but I have a different, almost opposite, question. I have a query I'd like to reuse as much as possible based on multiple "where" criteria which would be optionally "all" or some value based on a control.
Specifically, for example, I have a treeview control with a root and 4 nodes. The root, when selected means "all", the four other nodes represent detail levels in a space inventory (account, building, floor, room). When a user selects a node, I populate a text box on a form with the key field value. I also have some date fields on the form, and I had to set up parameters since the chart application squawks without them. Just one solution, would probably give them all, so in the following query sql, I'd like to control the [bldg cod] criteria to either be "all" or a selected building based on a control on a form. I know I could just build a sql string, but the issue is that this is just the first of 4 nested queries, so I would have an equally large mess if I had to build all the strings.
This is SQL view of the query:
PARAMETERS [Forms]![frmInspectionReports]![StartDate] DateTime, [Forms]![frmInspectionReports]![EndDate] DateTime;
SELECT DISTINCT [Building Inventory].[BLDG Code], [Building Inventory].[Building Name], IIf(IsNull([tblInspectionRecords].[DTimeStamp]),"Not Inspected","Inspected") AS Status, [Space Inventory].SF, [Space Inventory].SpaceID
FROM BidTable INNER JOIN ([Building Inventory] INNER JOIN ([Space Inventory] LEFT JOIN tblInspectionRecords ON [Space Inventory].SpaceID = tblInspectionRecords.SpaceID) ON [Building Inventory].[BLDG Code] = [Space Inventory].[BLDG Code]) ON BidTable.BidId = [Building Inventory].BidID
GROUP BY [Building Inventory].[BLDG Code], [Building Inventory].[Building Name], IIf(IsNull([tblInspectionRecords].[DTimeStamp]),"Not Inspected","Inspected"), [Space Inventory].SF, [Space Inventory].SpaceID, BidTable.CustomerCompanyName, tblInspectionRecords.DTimeStamp
HAVING (((tblInspectionRecords.DTimeStamp)>CDate([Forms]![frmInspectionReports]![StartDate])-1 And (tblInspectionRecords.DTimeStamp)<CDate([Forms]![frmInspectionReports]![EndDate])+1)) OR (((tblInspectionRecords.DTimeStamp) Is Null))
ORDER BY [Building Inventory].[Building Name];
This nomenclature, with spaces in the table and field names is poor, I know, but it's a legacy that traces back 20 years when I didn't know better coming out of a mechanical engineering background.
Specifically, for example, I have a treeview control with a root and 4 nodes. The root, when selected means "all", the four other nodes represent detail levels in a space inventory (account, building, floor, room). When a user selects a node, I populate a text box on a form with the key field value. I also have some date fields on the form, and I had to set up parameters since the chart application squawks without them. Just one solution, would probably give them all, so in the following query sql, I'd like to control the [bldg cod] criteria to either be "all" or a selected building based on a control on a form. I know I could just build a sql string, but the issue is that this is just the first of 4 nested queries, so I would have an equally large mess if I had to build all the strings.
This is SQL view of the query:
PARAMETERS [Forms]![frmInspectionReports]![StartDate] DateTime, [Forms]![frmInspectionReports]![EndDate] DateTime;
SELECT DISTINCT [Building Inventory].[BLDG Code], [Building Inventory].[Building Name], IIf(IsNull([tblInspectionRecords].[DTimeStamp]),"Not Inspected","Inspected") AS Status, [Space Inventory].SF, [Space Inventory].SpaceID
FROM BidTable INNER JOIN ([Building Inventory] INNER JOIN ([Space Inventory] LEFT JOIN tblInspectionRecords ON [Space Inventory].SpaceID = tblInspectionRecords.SpaceID) ON [Building Inventory].[BLDG Code] = [Space Inventory].[BLDG Code]) ON BidTable.BidId = [Building Inventory].BidID
GROUP BY [Building Inventory].[BLDG Code], [Building Inventory].[Building Name], IIf(IsNull([tblInspectionRecords].[DTimeStamp]),"Not Inspected","Inspected"), [Space Inventory].SF, [Space Inventory].SpaceID, BidTable.CustomerCompanyName, tblInspectionRecords.DTimeStamp
HAVING (((tblInspectionRecords.DTimeStamp)>CDate([Forms]![frmInspectionReports]![StartDate])-1 And (tblInspectionRecords.DTimeStamp)<CDate([Forms]![frmInspectionReports]![EndDate])+1)) OR (((tblInspectionRecords.DTimeStamp) Is Null))
ORDER BY [Building Inventory].[Building Name];
This nomenclature, with spaces in the table and field names is poor, I know, but it's a legacy that traces back 20 years when I didn't know better coming out of a mechanical engineering background.