Solved

No Data Subform

Posted on 2014-09-25
6
173 Views
Last Modified: 2014-09-25
I have a Dashboard/Switchboard Form that has a unbound subform, based on a query that looks at a score from an Answers Table.

On the Dashboard Form I have an unbound textbox "Text38"  which displays text based on the results of the percentage field in the subform, using the following code on the On Current Event:

If IsNull(Me!mjpMaxScore!Percentage) Then
Me!Text38.Visible = False
ElseIf Me!mjpMaxScore!Percentage >= 85 Then
Me!Text38 = "World Class"
ElseIf Me!mjpMaxScore!Percentage < 85 And Me!mjpMaxScore!Percentage >= 70 Then
Me!Text38 = "Good Operational Standard"
ElseIf Me!mjpMaxScore!Percentage < 70 And Me!mjpMaxScore!Percentage >= 40 Then
Me!Text38 = "Acceptable - Further Action Required"
ElseIf Me!mjpMaxScore!Percentage < 40 And Me!mjpMaxScore!Percentage > 0 Then
Me!Text38 = "Poor - Immediate Action Required"
ElseIf Me!mjpMaxScore!Percentage = 0 Then
Me!Text38 = "No Questions Answered or All Major N/C"
End IF

This works perfectly when there is data, but throws up "Runtime Error 2427 -you have entered an invalid expression that has no value"

How do I deal with this, please?

Thanks in anticipation.
0
Comment
Question by:SparkyP
  • 3
  • 2
6 Comments
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 40343741
<<How do I deal with this, please?>>

 Three possible ways:

1. add error trapping and trap the error.

2. Actually check the recordcount of the subform before performing the calc

3. Use the following code:

Function AvoidError(n As Variant, varReplaceWith As Variant)

10      On Error GoTo AvoidError_Error

20      If IsError (n) then
            AvoidError = varReplaceWith
         Else
            AvoidError = Nz(n, varReplaceWith)
         End If

AvoidError_Exit:
30      Exit Function

AvoidError_Error:
40      AvoidError = varReplaceWith
50      Resume AvoidError_Exit

End Function

Open in new window


 Put that in a standard module, then in your calc, do:

 AvoidError(<value>,0)

I find the last to be simplest.
0
 

Author Comment

by:SparkyP
ID: 40343809
Many Thanks Jim

The Calc is from a Query which has several Calcs that display in the subform, ie. Sum of questions, sum of question answered etc.

Obviously if no questions have been asked or answered the query has no results.

The percentage calc is the one that is used to display the text.

Sorry for any confusion.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40343895
So, is this code in the Current event of the subform?

Jim, like that AvoidError function, why didn't I ever think of that?  So, to avoid a divide by zero error, you would do something like?

Percentage: AvoidError([SomeField]/[SomeOtherField], 99)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SparkyP
ID: 40343913
Dale

On Current in the Main Form
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
ID: 40343943
Then, as Jim said, before you test anything else, check to see whether the subform has any records.

If me.subformControlName.Form.Recordsetclone.RecordCount = 0 then
   'do something
   me.subformControlName.visible = false
Else
   'your code goes here.
End if
0
 

Author Closing Comment

by:SparkyP
ID: 40344011
Thanks Both

Works like a dream
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question