nell'evento form unload o query unloadinsomma l'ultimo evento che gestisci come ultima istruzione scrivi
set nomeform = nothing