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
Solved

ms access #TYPE! error on report when no data

Posted on 2016-08-26
4
83 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 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

808 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