Avatar of Rob4077
Rob4077
Flag for Australia asked on

object invalid or no longer set

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
Microsoft Access

Avatar of undefined
Last Comment
Rob4077

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rob4077

ASKER
Thanks for that. Problem solved!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes