object invalid or no longer set

Rob4077
Rob4077 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
try

 If Me.cboDetailid.listcount=0 then

Author

Commented:
Thanks for that. Problem solved!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial