Tring to not get and error when null is received from Recordset

Posted on 2004-11-02
Last Modified: 2010-04-24
I have a record set that returns nulls in one of the fields.  The nulls are expected.  However I keep getting and error in the following code when a null is passed to the if then statement.  How do I keep for getting the null and choosing between the different types of greetings?


        emailSalutation = emailSalutation & "         <table width=600 border=1 cellpadding=10>" & vbCrLf
        emailSalutation = emailSalutation & "             <tr>" & vbCrLf
        emailSalutation = emailSalutation & "                 <td align='left'>" & vbCrLf
        If Len(rsEmailList("fldFirstName").Value) > 1 Then
            emailSalutation = emailSalutation & " <p>Dear " + rsEmailList("fldFirstName").Value + ",</p>"
            emailSalutation = emailSalutation & " <p>Dear Patron,</p>"
        End If
        emailSalutation = emailSalutation & "                 </td>" & vbCrLf
        emailSalutation = emailSalutation & "             </tr>" & vbCrLf
        emailSalutation = emailSalutation & "           </table>" & vbCrLf


thank you
Question by:GabicusC
    LVL 9

    Expert Comment

    Hi Gabicus,

    what is exactly the error message ?
    If (Not rsEmailList("fldFirstName").IsNull) Then
          If Len(rsEmailList("fldFirstName").Value) > 1 Then ...

    Hope this helps.
    LVL 6

    Accepted Solution

    if not isdbnull( rsEmailList("fldFirstName")) then ...

    this works with datatables/datasets, i assume it will treat recordsets the same, curious to know.

    Author Comment

    Hi noulouk,

    this is the error that I am getting:

    An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

    Additional information: Type mismatch.

    I tried what gave me but I get the error "isNull" is not a member of the ADODB.field


    Author Comment

    Well slyckboy it works with recordset also.

    Thank you

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 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

    22 Experts available now in Live!

    Get 1:1 Help Now