Solved

URGENT: Printing error when printing a empty field.

Posted on 2006-07-04
7
184 Views
Last Modified: 2010-04-23
Could someone please help me urgently!

I am trying to print the addresses of clients on an Access Database using VB.net.  But when one of the fields is empty I get an error.  I've tried putting


if not client("Add5") = ""
and
if not client("add5") = nothing

and cant avoid the error

any ideas?

Thanks
Bsturge
0
Comment
Question by:bsturge
[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
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:tsay
ID: 17035917
Try checking for DBNull values.

If client("Add5") <> "" and client("Add5") <> DBNull.Value then ...

HTH
0
 
LVL 9

Accepted Solution

by:
lojk earned 500 total points
ID: 17036006
I usually add a seperate function.. Reduces much typing time later...

        Public Shared Function CheckNullString(ByVal stringToCheck As Object) As String
                Dim tret As String = ""
                Try
                        tret = CStr(stringToCheck)
                Catch ex As Exception
'catch the error if you like...
                End Try
                Return tret
        End Function

then..

Console.writeline (checknullstring(client("Add5")))
0
 
LVL 1

Expert Comment

by:SteSi
ID: 17036248
try this:

IIf(VarType(client("Add5"))= VariantType.Null, "", client("Add5"))

This will return the value if it is not null and a blank string if it is null!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bsturge
ID: 17036261

Tsay,

Thanks for your solution.  The problem is that the value is DBNull but when I put the suggested line:

If client("Add5") <> "" and client("Add5") <> DBNull.Value then ...

I get this error:

 Operator '<>' is not defined for types 'System.Object' and 'System.DBNull'. Use 'Is' operator to compare two reference types.

0
 
LVL 5

Expert Comment

by:tsay
ID: 17036272
Oh,

then try this:
If client("Add5") <> "" and client("Add5) Is Not DBNull.Value then ...
0
 
LVL 5

Expert Comment

by:tsay
ID: 17036291
Ok that's also wrong so I took the effort of actually opening Visual Studio,

it should be this:

If client("Add5") <> "" and Not client("Add5) Is DBNull.Value then ...
0
 
LVL 9

Expert Comment

by:lojk
ID: 17037162
Not only has it got to work but you have to type it over and over and over and over again...

My way keeps your inline code nice and neat... (and also allows you to refactor the CheckNullString Function Later). Just for reference i also have a CheckNullNumber function that does the same but... well get you get the idea..

Thanks for the points..
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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