Determining if there are records in a subform...

B

Brad Pears

I have a subform that consists of the child entries relating to the parent
form. I want to make sure that data has been entered in this subform prior
to performing another function.

Is there a quick way to check the subform control to see if it contains
records or do I have to use an SQL clause to select records from the child
table and use the .recordcount property to determin if anything has been
entered?

Thanks,

Brad

Thanks,

Brad
 
S

Steve Schapel

Brad,

There are a number of ways to do this. Here are a couple:

Put an unbound textbox in the Form Footer section of the subform, with
the Control Source set to =Count(*) and then in your code you can use
soemthing like this...
If Not IsNumeric(Me.YourSubform.Form!YourCountTextbox) Then
MsgBox "No records entered yet"
Else
....
End If

Use a domain aggregate function...
If DCount("*","YourSubformQuery")=0 Then
MsgBox "No records entered yet"
Else
....
End If

.... or perhaps that would need to be...
If DCount("*","YourSubformQuery","[YourID]=" & Me.YourID)=0 Then
 
P

PC Datasheet

A fourth way and simple:
If Me!SubformControlName.Form.Recordsetclone.Recordcount <> 0 Then
Msgbox "There are records in the subform"
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
[email protected]
www.pcdatasheet.com



Steve Schapel said:
Brad,

There are a number of ways to do this. Here are a couple:

Put an unbound textbox in the Form Footer section of the subform, with
the Control Source set to =Count(*) and then in your code you can use
soemthing like this...
If Not IsNumeric(Me.YourSubform.Form!YourCountTextbox) Then
MsgBox "No records entered yet"
Else
....
End If

Use a domain aggregate function...
If DCount("*","YourSubformQuery")=0 Then
MsgBox "No records entered yet"
Else
....
End If

... or perhaps that would need to be...
If DCount("*","YourSubformQuery","[YourID]=" & Me.YourID)=0 Then

--
Steve Schapel, Microsoft Access MVP


Brad said:
I have a subform that consists of the child entries relating to the parent
form. I want to make sure that data has been entered in this subform prior
to performing another function.

Is there a quick way to check the subform control to see if it contains
records or do I have to use an SQL clause to select records from the child
table and use the .recordcount property to determin if anything has been
entered?

Thanks,

Brad

Thanks,

Brad
 
Top