If a modern corporation is going to hire someone 40 or older, they are going to hire someone with at least 20 years of experience.
Why? Simple economics.
Cost of providing healthcare, pension and similar benefits is higher for older workers. They also typically have families (or at least lives) outside of work that require some portion of their attention and enthusiasm that might otherwise be directed towards work. They aren't fresh college grads that will work 38 hour shifts without extra pay and brag about it.
Now, if the older worker has lots of experience, that totally justifies his higher cost. You cannot get decades of real world high tech work experience from somebody only 20 years old. Obviously the older worker also has to be good at the task - a half-assed chucklehead of a young worker might learn to do better (if not, the employer will want to get rid of him before he causes too much damage). But if a 40+ year old isn't already a recognized expert in his or her field, s/he's unlikely to become one any quicker than a younger, cheaper person would.
This is the way the system works. It's not because somebody's trying to discriminate against your age. It's because companies want to make money and they have to work within the framework that exists.
So, if you're over 40 and your heart is totally set on becoming a programmer, you'll need to look for work in fields that you have non-programming experience in. For example, if you spent the last 30 years doing fireproof construction, you can be a programmer for a concrete company or architectural engineering firm, because you can leverage your knowledge of masonry. If you have been building and racing cars for decades as a hobby, you can be a programmer for a racing or car company. But those kind of angles are the only way you'll get a decent programming job as a 40-year-old newbie. You'll have to capitalize on your experience, or some younger person will be able to do the job better for less money than you can survive on.