bsturge
asked on
URGENT: Printing error when printing a empty field.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
IIf(VarType(client("Add5")
This will return the value if it is not null and a blank string if it is null!
ASKER
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.
Oh,
then try this:
If client("Add5") <> "" and client("Add5) Is Not DBNull.Value then ...
then try this:
If client("Add5") <> "" and client("Add5) Is Not DBNull.Value then ...
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 ...
it should be this:
If client("Add5") <> "" and Not client("Add5) Is DBNull.Value then ...
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..
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..
If client("Add5") <> "" and client("Add5") <> DBNull.Value then ...
HTH