Question: The TOTALPAGES variable always returns 0.

Answer:

The report must be two-pass (go File|Report options in the designer).