checking subform for records?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 ...
 
Chris,

It sort of sounds like you are trying to create a wizard type flow where
each tab is in effect the next step in a wizard. If so, there are a couple
of routes.

If you want to stick with the Tab control, you could hide the tabs and then
based on some event (like the completion of a text field), you could check to
see if all of the necessary data is present and then make the next tab
visible.

Otherwise, perhaps look at creating a new form that has a Subform control
that you could toggle through each of the page views that you want to show
them in order. You could create a Control array that has them loaded and
then iterate through them as necessary.

Either way, you could then set the next tab/subform Source Object property
as required based on a previous step.

Lance



Chris said:
I think I might have explained my problem incorrectly.

I need to determine whether the subform has had a record source object
assigned to it.

I have a main form with a tab control with 3 pages on it.
When you click on the first page current record , this determines the records
in the 2 page tab. Then so on to the 3rd page tab.
When the form first loads if a user skips the 2nd tab page and goes straight
to
the 3rd page, there is an error when trying to assign input parameters to it
because
my input parameters is this:

sparam = "'" & Me.SubFormChild1.Form.Transit.Value & "'" & "," & "'" &
Me.SubFormChild1.Form.APP.Value & "'" & "," & "'" &
Me.SubFormChild1.Form.Currency.Value & "'"

there are no values because a recordset was neither created or a record made
current by user interface click on row.

I could juggle variables that determine my sequence but would prefer a
solution with more finesse.

I tried using tabcontrol.oldvalue to say that if the old value is 0 (first
page) then it must have skipped the second one, and hence don't run the code
but it always says there is no value assigned to this object.

thanks

Chris



LTofsrud said:
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




Chris said:
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
 
I think I might have explained my problem incorrectly.

I need to determine whether the subform has had a record source object
assigned to it.

I have a main form with a tab control with 3 pages on it.
When you click on the first page current record , this determines the records
in the 2 page tab. Then so on to the 3rd page tab.
When the form first loads if a user skips the 2nd tab page and goes straight
to
the 3rd page, there is an error when trying to assign input parameters to it
because
my input parameters is this:

sparam = "'" & Me.SubFormChild1.Form.Transit.Value & "'" & "," & "'" &
Me.SubFormChild1.Form.APP.Value & "'" & "," & "'" &
Me.SubFormChild1.Form.Currency.Value & "'"

there are no values because a recordset was neither created or a record made
current by user interface click on row.

I could juggle variables that determine my sequence but would prefer a
solution with more finesse.

I tried using tabcontrol.oldvalue to say that if the old value is 0 (first
page) then it must have skipped the second one, and hence don't run the code
but it always says there is no value assigned to this object.

thanks

Chris



LTofsrud said:
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




Chris said:
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
 
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
 
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
 
Back
Top