When is subform empty?

D

David Portwood

I have a main form with embedded subform linked 1-M. Is there an event in
the main form where I can find out if the subform is empty? I need this code
to trigger as the user browses the main form. Assuming there is such an
event, what code could I use to determine if the subform is empty? I suppose
a DCount() would work but that seems slow. I was thinking of using the
subform's Recordsource property in some way... I could use a little help
here. Thanks in advance.
 
D

Dirk Goldgar

In
David Portwood said:
I have a main form with embedded subform linked 1-M. Is there an
event in the main form where I can find out if the subform is empty?
I need this code to trigger as the user browses the main form.
Assuming there is such an event, what code could I use to determine
if the subform is empty? I suppose a DCount() would work but that
seems slow. I was thinking of using the subform's Recordsource
property in some way... I could use a little help here. Thanks in
advance.

You can use code in the main form's current event to check the subform's
recordset. For example:

'----- start of example code -----
Private Sub Form_Current()

If Me.sfMySubform.Form.Recordset.RecordCount = 0 Then
Me.lblEmpty.Caption = "Empty"
Else
Me.lblEmpty.Caption = "Full"
End If

End Sub

'----- end of example code -----

Note that, in the above, the name "sfMySubform" is the name of the
subform control (on the main form), not necessarily the name of the form
object that is displayed in that control.
 
A

Arvin Meyer [MVP]

You could try this in the Current event of the main form:

If Me.SubformControlName.Form.RecordsetClone.RecordCount = 0 Then
' Do something
End If
 

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