If statement with subform

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

Is the a way to perform an conditional if statement on a subfrom like this:
If Me.InScope_subform HasData then
Me.cmdViewReport.Enabled=True
Else If Me.InScope_subform doesn't HaveData then
Me.cmdViewReport.Enabled=False
End If
What I am trying to do is enable a command button if there are records in
the subform but I don't know which of the subform properties to use.
 
1) HasData is either True or False. Since there are no other possibilities:

If Me.InScope_subform.HasData then
Me.cmdViewReport.Enabled=True
Else
Me.cmdViewReport.Enabled=False
End If

This could also be expressed in one line:

Me.cmdViewReport.Enabled = Me.InScope_subform.HasData

2) HasData property is only available for Subreports, not Subforms. You
state Subform, but i'm not sure if you are just using the terms
interchangably. If you really are dealing with a subform, I believe
"Subform.Recordset.Recordcount >0" would be the HasData equivalent:
Me.cmdViewReport.Enabled = Me.InScope_subform.Recordset.Recordcount

3) Whether Subform or Subreport, "InScope_subform" in your code should
represent the name of the CONTROL containing the report/form, not the name
of the report/form itself. The two might be the same (depending upon how the
control was created), but if they are not, it is only the name of the
control that matters.
 
Thanks George,
But, I can't find Recordset.Recordcount in the property list for the
subform. My sumform name is "Inscope Site Summary subform1" and when I typed
Me.Inscope_Site_Summary_subform1., the only options I get are Report and
Requery.
 
Thanks a lot George. It worked.

George Nicholson said:
1) HasData is either True or False. Since there are no other possibilities:

If Me.InScope_subform.HasData then
Me.cmdViewReport.Enabled=True
Else
Me.cmdViewReport.Enabled=False
End If

This could also be expressed in one line:

Me.cmdViewReport.Enabled = Me.InScope_subform.HasData

2) HasData property is only available for Subreports, not Subforms. You
state Subform, but i'm not sure if you are just using the terms
interchangably. If you really are dealing with a subform, I believe
"Subform.Recordset.Recordcount >0" would be the HasData equivalent:
Me.cmdViewReport.Enabled = Me.InScope_subform.Recordset.Recordcount

3) Whether Subform or Subreport, "InScope_subform" in your code should
represent the name of the CONTROL containing the report/form, not the name
of the report/form itself. The two might be the same (depending upon how the
control was created), but if they are not, it is only the name of the
control that matters.
 
You need to reference the subform this way:

Me.InScope_subform.Report.HasData

Without .Report Access shows you the methods/properties of the subreport
CONTROL on the main report. With .Report, you tell Access to drill down to
the subreport itself and view its methods/properties. Same syntax for
Forms. You can occasionally get away by omitting these properties but that
potentially leads to trouble as you change Access versions. Some versions
are stricter about syntax than others. So save yourself grief down the line
and don't take shortcuts.
 

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

Similar Threads


Back
Top