All debtors receive the Automatic Stay of Proceeding when either a Chapter 7 or Chapter 13 is filed. Therefore, any pending Foreclosure sale must be cancelled or postponed as soon as your Bankruptcy case is filed with the Court.
A Chapter 7 filing maybe advantageous in preventing foreclosure if the debtor has a sale pending to a private party. However, in most cases, a Chapter 13 is the best solution for solving those foreclosure woes.
My office can put together a Chapter 13 Plan for you that will either cure all mortgage arrears (missing payments) within 60 months, or allow you more time to get the property sold to a private party.
Since you don't want to lose your investment, you must have your case filed before the Foreclosure sale takes place, if not, then all your remedies will be "foreclosed"