Referencing Subforms

D

DS

I have a Main Form (Sales) and a SubForm (SalesDetails) I want to close
the Main Form as well as the Subform but only if the Subform has No
Records in it. The command button is on the Main Form.
I tried this but it doesn't work.

If ISNull(Forms!Sales.SalesDetails!ItemID) Then
DoCmd.OpenForm "CantClose"
Else
DoCmd.Close
End IF

ItemID being a field on the SalesDetails Form, which is by the way based
on a Query, the SalesDetails Query.

Thanks
DS
 
A

Allen Browne

Try something like this:
If IsNull(Me.SalesDetails.Form!ItemID) Then
MsgBox "can't close."
Else
DoCmd.Close acForm, Me.Name
End If

For an explanation, see:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

BTW, it is possible that the Name of the subform control is different from
the name of the form it contains (its SourceObject.)
 

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