Results 1 to 4 of 4

Thread: Invalid us of Null

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    45
    When I run the following code:

    With rsPI
    txtFSN.Text = !FSN
    txtFirst.Text = !First_Name
    txtLast.Text = !Last_Name
    medSSN.Text = !Soc_Sec
    txtMI.Text = !MI_Name
    ...

    I get "Run time error '94': Invalid use of Null" with the
    debug pointing to the "txtFSN.Text = !FSN" line. If I comment that out and rerun it, I get the same error on the "txtMI.Text = !MI_Name" line. With that line (and the following assignment lines) commented out, the form displays OK.

    Can someone explain the concept of "Null" as used in this error message? And what I need to do to correct the problem?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Your database field has a null value
    change

    I think this will work
    txtFsn.datafield = format(rs("Field"))
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    You need to check for the return from your recordset is a NULL string before you assign it to the textbox control

    You can do it both way... But the IIF will be a bit slow, because it check both True and False condition before it make the decission

    Code:
    With rsPI
        txtFSN.Text = IIf(IsNull(!FSN), "", !FSN)
        txtFirst.Text = IIf(IsNull(!First_Name), "", !First_Name)
        txtLast.Text = IIf(IsNull(!Last_Name), "", !Last_Name)
        medSSN.Text = IIf(IsNull(!Soc_Sec), "", !Soc_Sec)
        txtMI.Text = IIf(IsNull(!MI_Name), "", !MI_Name)
    End With
    OR

    Code:
    With rsPI
        If IsNull(!FSN) Then
            txtFSN.Text = ""
        Else
            txtFSN.Text = !FSN
        End If
        
        If IsNull(!First_Name) Then
            txtFirst.Text = ""
        Else
            txtFirst.Text = !First_Name
        End If
        
        If IsNull(!Last_Name) Then
            txtLast.Text = ""
        Else
            txtLast.Text = !Last_Name
        End If
        
        If IsNull(!Soc_Sec) Then
            txtmedSSN.Text = ""
        Else
            txtmedSSN.Text = !Soc_Sec
        End If
        
        If IsNull(!MI_Name) Then
            txtMI.Text = ""
        Else
            txtMI.Text = !MI_Name
        End If
    End With

  4. #4
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Try this

    Code:
    With rsPI 
      
      txtFSN.Text = "" & !FSN 
      txtFirst.Text = "" & !First_Name 
      txtLast.Text = "" & !Last_Name 
      medSSN.Text = "" & !Soc_Sec 
      txtMI.Text = "" & !MI_Name 
    
    End With
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width