Solved

No Data Subform

Posted on 2014-09-25
6
167 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

813 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

15 Experts available now in Live!

Get 1:1 Help Now