Sometimes GotFocus event doesnt occur on subform...strange

J

Joe M.

I have a mainform and a subform (named Lookup_results). The subform is bound
to a query. There is a lookup button on the mainform with code DoCmd.Requery
"Lookup_results" followed by Me.Lookup_Results.SetFocus to populate the text
boxes on the subform. I want to have a msgbox appear when the query returns
no data. To do this I put this code in the GotFocus event of the subform: If
Me.RecordsetClone.RecordCount = 0 Then MsgBox.... I have not set focus to any
of the controls on the subform. So far everything works correctly....until I
added another text box to the subform. Now the GotFocus event on the subform
doesn't occur when there's no data. If I remove the newly added text box then
everything works correctly again. Why not? I need to add the textbox to the
subform.
Thanks in advance, Joe M.
 
S

S.Clark

I remember GotFocus being flakey.

After the DoCmd.Requery, check the number of records of the subform and skip
the GotFocus attempt.

If Me.sfrmName.form.recordcount = 0 then
msgbox "No records found"
End if

Or, do a DCount to the query before the Requery to determine if it's even
worth doing the requery.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top