How set focus to sub form?

M

mscertified

I have a form and a subform with a one-many relationship. Before I exit the
form, I must validate that there is at least one row in the subform.
Is there an easy way to do this?
Also, if there is no row, I display a msgbox and then need to set focus to
the subform, how? I tried the syntax in my Access book and it does not work.
Here is what I used:

Me.Controls("frmCorrespRuleXref_subform").Form.Controls("Chapter").SetFocus
 
O

Ofer

On the unload event of the form write the code
' To check if any records were entered
If Me.SubFormName.Form.RecordsetClone.RecordCount = 0 then
cancel=true ' Wont let exit the form
me.SubFormName.Form.FieldName.SetFocus ' Set the focus to the field
exit sub
End if
 
Top