Likely what is happening is the gain on the 4797 is carrying to Schedule D as capital gain income. Capital gain income is not allowed to be used in the definition of "investment income" when determining the deductibility of investment expense. The reasoning being that capital gains are taxed at a lower rate.
If on your 4797 you have any recapture of depreciation in Part II that is considered ordinary income and could be added as investment income for purposes of determining the deductibility of the interest expense.
So - if you gain is in Part I or Part III on the 4797, it cannot be used in determining investment expense. If it is Part II it can be used.
Hope that clarifies. If you have a further question, please hit the need info button and ask. If you are satisfied with the answer please hit the green accept button to close out the question and allow me to receive payment.