Buongiorno a tutti, chiedo Vostro consiglio su quale e' il modo corretto di procedere: ho diverse situazioni in cui ho l'apertura di recordset condizionati come nell'esempio seguente.
Private Sub Form_Current()
On Error GoTo Err_handler
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset
If Me.sfrmRCcboNUMtabRCIDtabOEid.Value <> 0 Then
Set rst = DBEngine(0)(0).OpenRecordset("SELECT * FROM tblOEoffertecostamp WHERE IDtabOEid=" & Me.sfrmRCcboNUMtabRCIDtabOEid, dbOpenSnapshot, dbReadOnly)
Me.sfrmRCchkflagoffertaevasa.Value = rst.Fields(8)
sfrmRCchkflagoffertaevasa.Requery
rst.Close
Set rst = Nothing
Else
Me.sfrmRCchkflagoffertaevasa.Value = False
End If
If Me.sfrmRCcboNUMtabRCIDtabONid.Value <> 0 Then
Set rst1 = DBEngine(0)(0).OpenRecordset("SELECT * FROM tblONordiniclienti WHERE IDtabONid=" & Me.sfrmRCcboNUMtabRCIDtabONid, dbOpenSnapshot, dbReadOnly)
Me.sfrmRCchkflagordineevaso.Value = rst1.Fields(6)
sfrmRCchkflagordineevaso.Requery
rst1.Close
Set rst1 = Nothing
Else
Me.sfrmRCchkflagordineevaso.Value = False
End If
sfrmRClstNUMtabRCIDtabEDid.Visible = Me.NewRecord 'listbox visibile con NewRecord
sfrmRCctrtxtattrezzista.Visible = Not Me.NewRecord 'textbox non visibile con NewRecord
sfrmRCcboNUMtabRCIDtabANid.Requery
Exit_Err_handler:
Exit Sub
Err_handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Err_handler
End Sub
Mi sono accorto che se la routine dovesse andare in errore dopo l'apertura di un recordset, questo teoricamente rimarrebbe aperto perche' si attiva la procedura dell'Err_handler e si chiude la Sub con il rst aperto.
Ho provato a spostare la sua chiusura dopo Exit_Err_handler, ma va in errore perche' se il recordset non e' stato aperto ovviamente non lo puo' chiudere.
Quindi quale e' il corretto modo di operare? Si puo' verificare se un recordset e' stato aperto?
Grazie in anticipo