Hi,
If you provide a recordsource to a subform and the query returns no records
you can basically do a record count to determine if there is at least one
record.
I need a way to determine if the recordsource has'snt even been set you.
If you try to access properties on a subform that has never recieved a
recordsource
almost everything returns an error.
I purposefully want to determine if subform is in this state without
resorting to error trapping and handling.
Is there a way?
thanks
Chris
Allen Browne - 31 May 2005 16:22 GMT
For this example, assume a subform control name Sub1, and the code examples
are in the main form's module.
You can determine If Sub1 has no form loaded into it by testing its
SourceObject property:
If Len(Me.Sub1.SourceObject) = 0 Then ...
If the subform control does have a SourceObject assigned, but there are no
records in the subform, you can examine the RecordCount of the
RecordsetClone of the Form in the subform control:
If Me.Sub1.Form.RecordsetClone.RecordCount = 0 Then ...

Signature
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.
> Hi,
>
[quoted text clipped - 17 lines]
>
> Chris
LTofsrud - 01 Jun 2005 00:08 GMT
Hi Chris.
I think that the following should do it for you.
if Me.[SubFormName].SourceObject <> "" then
' Do what ever you want now that you know that the Source Object is set
to a valid table or subform.
end if
Let me know if this isn't what you are referring to.
Lance
> Hi,
>
[quoted text clipped - 16 lines]
>
> Chris
LTofsrud - 01 Jun 2005 00:09 GMT
Chris,
Try:
if Me.[subFormName].SourceObject <> "" Then
' Perform task.
else
' Bind the appropriate table or subform
End if
I've done this quite a bit when switching dynamically betwee subforms. You
can even enhance it with a DCount to ensure that there are records available
as well.
Let me know if you were looking for something else.
Lance
> Hi,
>
[quoted text clipped - 16 lines]
>
> Chris