I'll guess at the stray "End If" on the third last line; without knowing the error, all we can do is guess - that may not be what's causing your error if there's an "If" further up in the code. If there is then set the recordset to nothing, before the "End If".
Search is your friend “I was having a mildly paranoid day, mostly due to the fact that the mad priest lady from over the river had taken to nailing weasels to my front door again.”