I think it's best not to depend on the record numbers. Look at the data instead.
For instance, I think here you are trying to treat the login differently depending on what is in username and password:
Call uname.Keys("^a")
Call uname.Keys("[BS]")
if rec <> 2 and rec <> 5 then
Call uname.Keys(Driver.Value(0))
end if
Call uname.Keys("[Tab]")
Call pwd.Keys("^a")
Call pwd.Keys("[BS]")
if rec <> 3 and rec <> 5 then
Call pwd.Keys(Driver.Value(1))
Try instead just entering whatever is in the UserName and Password fields, or if you do want to skip, check the data as you go. Something like:
If UserName <> blank then
Call uname.Keys(Driver.Value(1))
Else
Call uname.Keys("[Tab]")
I don't have your syntax right but hopefully you will see what I mean. That will work for all your records and you don't need the records to be in a particular order and you don't need to know what the particular scenario is every time.