Solved

No Data Subform

Posted on 2014-09-25
6
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

739 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