Solved

No Data Subform

Posted on 2014-09-25
174 Views
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
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
• 3
• 2

LVL 57

Assisted Solution

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

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

AvoidError(<value>,0)

I find the last to be simplest.
0

Author Comment

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.

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

Sorry for any confusion.
0

LVL 47

Expert Comment

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

Author Comment

ID: 40343913
Dale

On Current in the Main Form
0

LVL 47

Accepted Solution

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
End if
0

Author Closing Comment

ID: 40344011
Thanks Both

Works like a dream
0

Featured Post

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.
Suggested Courses
Course of the Month8 days, 2 hours left to enroll