I have a form with a few controls that affect the recordsource of a combo box on my form so I have set the On GotFocus event of the combo box to requery, which works fine. I then tried to extend the code to set the value to the first record in the underlying recordset if there's only one element in the recordset (see the code below). The requery runs fine but I get an "object invalid or no longer set" error in the line that follows the requery. Any suggestions as to what might be causing the error?
Me.cboDetailid.Requery
If Me.cboDetailid.Recordset.RecordCount = 1 Then '<<< the error occurs here
Me.cboDetailid = CLng(Me.cboDetailid.ItemData(0))
End If