467,892 Members | 1,851 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,892 developers. It's quick & easy.

Subform not displaying due to missing record

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
  • viewed: 3532
Share:
2 Replies

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
That did it. Thanks!

Jun 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Darryl Kerkeslager | last post: by
5 posts views Thread by Thelma Lubkin | last post: by
1 post views Thread by jeremy0028 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.