To have full auto focus with a D40 the lens must be an AF-S or AF-I lens. These lenses have their focus motor in the lens; the D40 doesn’t have an internal focus motor. They have been manufactured since about 1992 so there are plenty of good used one available. Sigma makes a series of outstanding lenses that complement the Nikkor line called HSM. They also have internal motors.
Keep in mind the real beauty of your D40 is that it can use any Nikon F lens made since 1959, except for the original fisheye that required mirror lock-up. There isn’t much in this world that has that kind of durability. The main reason I have a D40 is so I can take one of the great lenses I been using for over forty years, click it on and have the latest technology with classic quality optics.
Look at the contacts on the rear of the lens. If the lens has one contact, a space, and 4 or 5 more it will AF on the D50 etc but not on the D40-60. To Focus on the D40-60 it needs seven or eight regularly spaced contacts on the lens. Also it will contain the motor and will specify that on the box.