In the updated OptiPlex 7040M Owner's Manual, 2016 - 07 Rev. A03, page 40, it says
Memory capacity 4 GB, 8 GB, and 16 GB
Maximum memory 32 GB
NOTE: Each memory module slot supports a minimum of 4 GB and a maximum of 16 GB.
But I wonder whether it really supports 32 GB memory.