Form/SubForm Syntax help

G

Gary Dolliver

Hi all,
I have a form with 5 subforms and am attempting to perform calculations on
the main form based on the information provided from the subforms. A problem
I am running into is there will be instances where a subform will not appear
as there will be no data, but then I receive a runtime error that the
expression has no value. How would I code this to just ignore the
calculation if one or more subforms do not appear? Here is an example
calculation:
Typing.Value = Me![EE].Form!Typing / Me![PIC].Form!Typing ----what would I
do if subform EE has no data?
Would I need to set up all the potential fields as variables on the main
form load, and then run the calculations from there? Or is there another way
I could do this?
Help is always appreicated, thanks
-gary
 
M

Marshall Barton

Gary said:
I have a form with 5 subforms and am attempting to perform calculations on
the main form based on the information provided from the subforms. A problem
I am running into is there will be instances where a subform will not appear
as there will be no data, but then I receive a runtime error that the
expression has no value. How would I code this to just ignore the
calculation if one or more subforms do not appear? Here is an example
calculation:
Typing.Value = Me![EE].Form!Typing / Me![PIC].Form!Typing ----what would I
do if subform EE has no data?


You can check for an empty subform by testing the subform
for no records. Here's a way to do that:

Typing.Value = IIf(Me![EE].Form.Recordset.RecordCount>0,
Me![EE].Form!Typing, Null) /
IIf(Me![PIC].Form.Recordset.RecordCount>0,
Me![PIC].Form!Typing, Null)

That's supposed to be all on one line.
 
G

Gary Dolliver

awesome, thanks again Marshall

Marshall Barton said:
Gary said:
I have a form with 5 subforms and am attempting to perform calculations on
the main form based on the information provided from the subforms. A problem
I am running into is there will be instances where a subform will not appear
as there will be no data, but then I receive a runtime error that the
expression has no value. How would I code this to just ignore the
calculation if one or more subforms do not appear? Here is an example
calculation:
Typing.Value = Me![EE].Form!Typing / Me![PIC].Form!Typing ----what would I
do if subform EE has no data?


You can check for an empty subform by testing the subform
for no records. Here's a way to do that:

Typing.Value = IIf(Me![EE].Form.Recordset.RecordCount>0,
Me![EE].Form!Typing, Null) /
IIf(Me![PIC].Form.Recordset.RecordCount>0,
Me![PIC].Form!Typing, Null)

That's supposed to be all on one line.
 

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

Top