Okay boys and girls, repeat after me: megapixels don't
count.
The picture below is one third the size of a 6-megapixel
shot:

Now if that's not enough resolution for you, much less three
times that, you really should be riding wind currents and looking
for field mice to eat.
Forget megapixels and look at low-light performance
instead. This is where the D40 and the other CCD-based Nikons
fall flat. Since they switched to CMOS, they've started to
catch up with Canon, but if you're looking for something in the
D40's bracket, forget it.
Now, as an alternative to the D40, I'd suggest the Canon
30D. It's got a CMOS sensor that handles low light better and
if you've still got a hard-on for megapixels it's got 8.2.
It's got an advantage over the 20D because the shutter life has
gone up from 50,000 to 100,000 actuations. Get one that
hasn't been banged about and it'll serve you well. The
problem is finding one - most 30D users I know are so happy with it
that they've kept it even though they've bought newer bodies.
If you can't find a 30D, I can personally vouch for the 400D -
the Eiffel Tower shot was taken with my old 400D and I still keep
it as a backup and for my wife to use. A reasonable-condition
example should set you back about $500-600. In terms of
low-light performance it's no slouch either. Here's a
sample:

Now, we've taken care of the less important part. Your
money's best spent on good glass. You want it sharp and you
want it fast.
For beginners, the EF 17-55 2.8 IS is pretty good for
beginners. The f/2.8 aperture is fast enough for most
applications and on a crop body, some people think it's actually
sharper than the 24-70 2.8L (I think that's wishful thinking,
though).
Still and all, I doubt you'd like the $1500 (minimum) price
tag.
More realistically, something like the Tamron 18-270 VC might be
more up your alley - it's got the range to handle almost
anything. Supposedly the sharpness is better than that of the
Sigma 18-200 OS I used to take the Eiffel Tower shot. The
Tamron's aperture of f/3.5-6.3 isn't anything to write home to mom
about, but for the $900 price tag, there's only so much you can ask
for and the image stabilisation does take some of the pain
away.