[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ms access #TYPE! error on report when no data

Posted on 2016-08-26
4
Medium Priority
?
209 Views
Last Modified: 2016-09-07
Hello-

 I have an MS access report. Run perfect when where is data.   If there is NO data I get a #Type!  error on a particular field

In the  report itself, under the detail section I have a text box that contains a  TRIM statement:   =Trim([PRIMARY_NAME]) & " " & Trim([Label_NAME])

If there is no data on the report, I get #Type!  error showing on the report when I run the print preview.

I tried to modify the trim statement to be :   =IIf(IsNull([PRIMARY_NAME])," ",Trim([PRIMARY_NAME]) & " " & Trim([Label_NAME]))       but that did not work.

I wrote it so if the PRIMARY_NAME field was null then it would just output a blank space. This was probably wrong because there is 2 fields in my trim statement.


I am probably missing something simple....  can someone give advice how to get rid of that #Type! error?  Thank you.
0
Comment
Question by:joylene6
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 41772553
IsNull vs Nz()
IsNull returns a Boolean, true or false
Nz(TheNullItem, TheSubstitute) substitutes something for the null.

Why are you TRIMing?
You should take care of that earlier.
Here's a fun trick.
In the query create two computed fields
tPRIMARY_NAME:Trim(PRIMARY_NAME)
tLabel_NAME: Trim(LABEL_NAME)

Make your control
=[tPRIMARY_NAME] + " " + [tLabel_NAME]

Only in Access controls does the + concatenation propogate null.
You'll only get the text of the Primary name, the text of the Label name, or both with a space in between.
0
 
LVL 1

Author Comment

by:joylene6
ID: 41772585
I was/am concatenating  the 2 fields.  I could put them together in the query.  
Just wondering if there was a way to do this in the report.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 41772873
The problem with an empty recordset is that you don't even get a NULL, but #Error.

Paste the following code into a standard module:

Function AvoidError(n As Variant, varReplaceWith As Variant)

10      On Error GoTo AvoidError_Error

20      AvoidError = Nz(n, varReplaceWith)

AvoidError_Exit:
30      Exit Function

AvoidError_Error:
40      AvoidError = varReplaceWith
50      Resume AvoidError_Exit

End Function

 and make sure you call the module something other then AvoidError if it's a new module.  Then make your control source:

=AvoidError(Trim([PRIMARY_NAME]) & " " & Trim([Label_NAME]),"")

This doesn't always work in all cases though.  Microsoft built in some optimizations that defeat this in some cases.  So sometimes you need to break it up in to two steps; A hidden control with your expression, then a visible control with =AvoidError(<visible control>).

The other way to do this is to either check the recordcount in your IIF statement or hasdata and if no records, display a blank (this is looking at a subreport):

IIf(me.rptMonthlyStatCo.report.HasData, Trim([PRIMARY_NAME]) & " " & Trim([Label_NAME]),"")

I find AvoidError() easier to use and it works most of the time without issue.

Jim.
0
 
LVL 1

Author Closing Comment

by:joylene6
ID: 41788343
Thank you for explaining this to me. It did happen to work.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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 …
Suggested Courses

834 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