you have the if statement at line 1.
the recordset is not created till line 41.
you wont be able to use the data in the recordset in your if statement till the recordset is created by the code.
the if statement needs to be moved so it is after the recordset.