You are closing the variable 'rs' and then setting it to nothing. But your connnection to the database is set in the 'rsKey' variable so you should be closing 'rsKey' instead. Basically change the code which shuts down the connection torsKey.close
set rsKey = nothing