Input validation, expect error on null input
The line
if tname is equal to &quot;&quot; then display dialog &quot;error&quot;

is never reached while tname is empty. You need to put it inside the loop.