Variables defined outside of a function aren't available within a function by default in PHP except for $_SESSION, $_GET, $_POST, $_SERVER, and $GLOBAL variables.
The solution is to define it as a global in the first line of the function like:
global Recordset1;