Your challenge with moving pictures at night is multiple fold.
- Because its dark you need to let in as much light as possible. So your Aperture needs to be as wide open as your lens allows.
- Because it is dark you need to have as high an ISO setting as possible.
- Because it is dark your flash may not be enough because the object is too far away.
- Moving objects need a fast shutter and that's where the above two may not be enough to give you a fast enough shutter.
The problem with changing the Aperture to be wide open is that your depth of field is greatly reduced. So objects within close proximity will not be focused evenly (one object more so than the other).
The problem with high ISO setting is that you will get a very grainy picture. This link should give you a better idea how well your D40 will perform at higher ISO settings
(Nikon D40 Review: 17. Photographic tests: Digital Photography Review). It looks like you might be ok around ISO 800 and anything above that your picture will be grainy.
Your flash also may not be strong enough especially if the object is too far away (i.e. further than around 20 feet). If your setting is Auto then the flash will go off and the camera will over compensate by a combination of shutter speed and aperture which results in a dark picture.
Now moving objects need a faster shutter (generally faster than 1/25). The faster the object the faster the shutter speed required.
So the bottom line is that you need to balance all the above. You might need to experiment a little and go outside under similar conditions and set your ISO to 800, your aperture to the widest your lens allows, your speed to 1/60, your flash on and take a picture of a moving object at similar speeds. Start from there and see if you need to increase or decrease the various settings (Aperture, Speed, ISO).
Good luck.