You probably mean:
If[ Get(LastError) = 401]
P.S. It may be better to generalize your custom dialog to handle all errors instead of just '401' by using: If[ Get(LastError) > 0]
And sometimes you need to use:
Set Variable [$ErrorCode ; value: Get ( LastError ) ]
Get (LastError) will not return an error code unless it is executed immediately after the script step that may have produced an error. Put even one other (successfully executed) script step between the two and no error code is returned. Thus, saving the code in a variable is sometimes a useful approach to use.
Thanks Jade and PhilModJunk.
Jade's answer solved my immediate problem. All working fine now. It's the little things that get you.
Learned important point, for future reference, from PhilModJunk's reply.
Thanks again, on with the show!