The Nikon DSLRs are an interesting bunch. Some of them support the older lenses.. some of them can’t. The older AF lenses used a drive from the camera body to focus the lens. Newer Nikons have the lens AF motor in the lens body.
D90 – This has the in-body motor drive for older AF lenses. It is also supposed to be able to handle the old manual ‘F’ lenses. You may need to switch the camera body to manual focus – as well as run the shutter/aperture in manual.
D40 – Different beast. It does not have the ‘in-body’ focus motor. It is only designed for AF-I/AF-S type lenses. As for the older all manual F mounts, I am uncertain as to whether they will work with a D40.
NOTE: To use the old F mount lenses on these bodies, you may need to change the switch setting on the lens that controls the aperture step down when a shot is taken. It tends to be a small switch near the aperture ring with the switch moving forwards/backwards.