By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Subform not displaying due to missing record

P: n/a
I have a parent form with two subforms on it. Each subform lists
certain records and then totals up one of the fieldsd. The parent form
then totals up the two text boxes. The problem is that if there are no
records for one of the subform's query, then I get an error (obviously
you can't add a value from a text box if it does not exist...):

Subform 1:

ItemX 10
ItemY 5
ItemZ 14

Subtotal1 29

Subform 2:

ItemA 1
ItemB 4
ItemC 45

Subtotal2 50

Parent form:

Grand Total 79

I tried using an IIF() to see if the subform's text box was null

=IIF
(
IsNull(rpt.Report!txt1), 0, rpt.Report!txt1) +
IsNull(rpt.Report!txt2), 0, rpt.Report!txt2)
)

but that still gave me an error. Any suggestions?

Thanks!
Mike

Jun 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

If a form has no records and no new records can be added, its Detail section
goes completely blank. Then referrring to the non-existent text box results
in an error.

To work around that, test The RecordCount of the RecordsetClone of the form
to see if there are any records:
=IIf([Sub1].[Form].[RecordsetClone].[RecordCount] = 0, 0,
Nz([Sub1].Form![txt1],0))

You example suggests this might be a report. If so, see:
Bringing the total from a subreport onto a main report
at:
http://allenbrowne.com/casu-18.html

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

"Mike" <lo********@gmail.com> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
I have a parent form with two subforms on it. Each subform lists
certain records and then totals up one of the fieldsd. The parent form
then totals up the two text boxes. The problem is that if there are no
records for one of the subform's query, then I get an error (obviously
you can't add a value from a text box if it does not exist...):

Subform 1:

ItemX 10
ItemY 5
ItemZ 14

Subtotal1 29

Subform 2:

ItemA 1
ItemB 4
ItemC 45

Subtotal2 50

Parent form:

Grand Total 79

I tried using an IIF() to see if the subform's text box was null

=IIF
(
IsNull(rpt.Report!txt1), 0, rpt.Report!txt1) +
IsNull(rpt.Report!txt2), 0, rpt.Report!txt2)
)

but that still gave me an error. Any suggestions?

Thanks!
Mike

Jun 29 '06 #2

P: n/a
That did it. Thanks!

Jun 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.