Age limit is completely waiverable.
Nuts, I wish I could remember the guys name.... some fairly famous surgeon joined right after 9-11, he was in his late 50s, I met him down at Ft Sam (well, I was briefly introduced to him to be truthful <g>)...
Anyway, YES, if after you finish your training, you decide to join the military, you will be able to.
I'm also a surgery R2, 40 years old, already in the military. My story is a little different because I spent most of those intervening years in the military though - I "came up" through the system if you will.
Suggestion: complete your program, obtain any sub-specialty training you are interested in, and if you still have the desire, contact a health professions recruiter of the service of your choice (we are all generally biased towards our own services, but I seem to hear worst things about the USAF than I experience in the Army - from Galo mainly).
Obtaining sub-specialty training first will ensure you don't get assigned to a smaller army hospital where Galo's comments about being a gastroenterologist tend to be more likely...
Then again, if you contact the recruiters as a graduating chief resident, you might be able to request / demand assignment to a better hospital (make sure anything like that is in WRITING in your contract. There is no such thing as a gentleman's agreement).
Most subspecialty training is done at civilian fellowships anyway, there are only a very few that the military does in-house, and even for those (vascular, CT, can't think of anything else) the majority of people go to civilian fellowships- but sometimes they are required to do a year or three as a bread & butter general surgeon at a small, out-of-the-way army base to pay their dues, so I would NOT look to do your fellowship after you come in to the military, in your current situation.
If you have a crushing debt burden, the military has loan repayment programs in exchange for a longer commitment. If your debt burden is manageable, then I would suggest avoiding such programs because it gives you more flexibility to walk away should the army stick you in a very undesirable location with a low case load, etc.
Don't get me wrong, I'm not one of those "hate the army" types who always pines for my freedom. But you need to realize that the "Needs of the Army" always comes first when it comes to personnel decisions, and many times the "Needs of the Army" do not correlate with the "Career Goals of the Individual".
Good luck, and feel free to pm me off line with any other questions.