Solved

No Data Subform

Posted on 2014-09-25
6
160 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
Comment Utility
<<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
Comment Utility
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)
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:SparkyP
Comment Utility
Dale

On Current in the Main Form
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
Comment Utility
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
Comment Utility
Thanks Both

Works like a dream
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now