I am trying to requery a recordset so that a form changes record based on a combobox. In the form's Open event I'm using this code:
What I'm trying to figure out is how to requery the recordset in the AfterUpdate event of the combobox without having to repaste all my code from the OnOpen event (if possible). I tried this but it doesn't work:
I get the error message: "Operation is not allowed when the object is closed". What object is closed? Any suggestions?
Code:
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
cn.Open CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM StdDegReq WHERE PersonId = " & Nz(Me.txtPersonId, 0)
rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic
Set Me.Recordset = rs
Exit_Procedure:
cn.Close
Set rs = Nothing
Exit Sub
Code:
Dim rs As ADODB.Recordset
Set rs = Me.Recordset
rs.Requery
Comment