The DCount() is probably better than looping through the records of the
subform. It works reliably, which may not be the case for the subform (e.g.
if filtered, or timing issues if it were not loaded yet.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"David Portwood" <(E-Mail Removed)> wrote in message
news:4788280c$0$7157$(E-Mail Removed)...
>I have a record for each contractual document (let's leave it general,
>please). Actions are generated against that document. When all actions have
>been resolved, the "owner" of the contractual document indicates completion
>of document processing by filling in a DateCompleted field.
>
> My Documents table is linked 1:M to an Actions table and I have a
> corresponding form/subform. I want the DateCompleted field in the main
> form to be disabled while there are any open Actions in the subform. To
> check for this, what I do now is run a DCount() against the Actions table.
> This works, but it seems unnecessarily time consuming to run a domain
> aggregate function when the records are right there on the subform. It is
> rare to have more than five actions for any one document.
>
> The subform is in datasheet view, so I can't put a calculated field. I
> tried code like the following in the main form's Current() event:
>
> With Me.Actions.form.recordset
> .findfirst "criteria indicating an open action"
> Me.DateCompleted.enabled = .no match
> end with
>
> Doesn't work, I forget specifically why now. Anyway, the DCount() works,
> but I'm hoping someone might have a faster way to do this.