Use the formula for compounded interest: A = Pert where A is the final amount, P is the initial amount, r in the rate as a decimal, and t is the time.
40000 = 8000 e0.07t (Divide both sides by 8000)
5 = e0.07t (Take the natural log of both sides)
ln 5 = 0.07t (Divide both sides by 0.07)
ln 5 / 0.07 = t
t = 23.0 years