Is it possible to comment code out in the SQL window in Microsoft Access?
Depending on your needs you can use the "Description" field on the query "Properties" dialog box:
.
No. You cannot have any extraneous text in Microsoft Access (JET-SQL).
You can make some constraints ignored, e.g.,
Where
name = "joe"
OR
(state = "VA" AND 1=0)
But that technique is a rather limited way to hide existing SQL.
As MathewMartin said, you can't. I use the following workaround:
SELECT * FROM x
WHERE "-- your comment. This plain string is always true";
or
SELECT * FROM x
WHERE y = 'something'
AND " -- z = 'something else' ";
Depending on your needs you can use the "Description" field on the query "Properties" dialog box:
.
Access gives you the option of invoking queries from a VBA sub, which obviously can be commented to your heart's content:
' Ensure that the AddressCurrent in tblAddresses only has one item marked.
' Assume the latest.
strSQL = _
"UPDATE tblAddresses " & _
"SET AddressCurrent = 0 " & _
"WHERE AddressCurrent = True "
' A comment can go in the middle if need be!
strSQL = strSQL & _
"AND AddressNumber NOT IN " & _
"(SELECT MAX (AddressNumber) " & _
"FROM tblAddresses " & _
"WHERE AddressCurrent = True);"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
While having to run a macro that uses DoCmd might seem slightly tedious, it does compensate with other advantages; I've listed a few examples below.
- Possibility of dynamic scripts
- Ability to bind the execution of the SQL to form buttons and other controls
- Locked white space, making queries actually easier to read
Another option would be to have a separate table named 'README' where you can have 2 fields i.e. ObjectName, Comments
This way you can have a memo field where you can mention important points regarding the SQL e.g. "Replace * with [Fname] to get only Full Name"
© 2022 - 2024 — McMap. All rights reserved.