Results 1 to 6 of 6

Thread: [RESOLVED] Search function - Invalid use of Null

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Location
    Netherlands, Wateringen
    Posts
    24

    Resolved [RESOLVED] Search function - Invalid use of Null

    Hi there,

    In my VB6 programm I use the following code in order to search in the Access DB. It looks like it's working fine, until...
    This time I want to search for the V-number (V9). In the DB are present the V9 and the V90(!) and here starts the problem. When I search for the V9 I receive a invalid use of Null and when I search for V90 I receive the right anwser.

    The code I use is:
    Code:
    Private Sub cmdZoekVnummer_Click()
    
    Dim strSQL As String
    strSQL = "SELECT * FROM tbl_Reparaties"
    
    If txtZoekVnummer.Text <> "" Then
            strSQL = strSQL & " WHERE fldVnummer LIKE '" & Trim(Replace((txtZoekVnummer.Text), "'", "''")) & "%'"
    End If
    
    rs1.Close
    
    rs1.Open strSQL, cn1, adOpenKeyset, adLockPessimistic, adCmdText
        
    If Not (rs1.BOF = True Or rs1.EOF = True) Then
           txtZoekVnummer.Text = ""
        End If
    
    FillFields
    
    End Sub
    The strange thing is that at debug the yellow line gets at the Fillfield

    Code:
    Public Sub FillFields()
    
        If Not (rs1.BOF = True Or rs1.EOF = True) Then
    
            txtDatum.Text = rs1.Fields("fldDatum")
            txtVnummer.Text = rs1.Fields("fldVnummer")
            txtMerk.Text = rs1.Fields("fldMerk")
            txtSerienummer.Text = rs1.Fields("fldSerienummer")
            txtType.Text = rs1.Fields("fldType")
            txtSoort.Text = rs1.Fields("fldSoort")
            txtKlacht.Text = rs1.Fields("fldKlacht")
            txtAccessoires.Text = rs1.Fields("fldAccessoires")
            txtStatus.Text = rs1.Fields("fldStatus")
    
    'this line below is yellow        
            txtBedrijfsnaam.Text = rs1.Fields("fldBedrijfsnaam")
    
            txtProject.Text = rs1.Fields("fldProject")
            txtLocatie.Text = rs1.Fields("fldLocatie")
            txtContactpersoonVoornaam.Text = rs1.Fields("fldContactpersoonVoornaam")
            txtContactpersoonTussenvoegsel.Text = rs1.Fields("fldContactpersoonTussenvoegsel")
            txtContactpersoonAchternaam.Text = rs1.Fields("fldContactpersoonAchternaam")
            txtContactpersoonTelefoon.Text = rs1.Fields("fldContactpersoonTelefoon")
            txtContactpersoonEmail.Text = rs1.Fields("fldContactpersoonEmail")
            
        End If
    
    End Sub
    I looked extra at fields from fldBedrijfsnaam and the following (order as in the code), but could not find any difference with the first like fldVnummer and fldMerk etc.

    Looking to many threads didn't gave me the anwser for this problem, so I hope someone is able to help me with this.

    Thanks

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Search function - Invalid use of Null

    It is because, in one of your records, the fldBedrijfsnaam field is having a Null value (empty). That's what I think...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    New Member
    Join Date
    Jan 2010
    Posts
    1

    Re: Search function - Invalid use of Null

    You can change a null to a string by appending a string to it.

    txtBedrijfsnaam.Text = rs1.Fields("fldBedrijfsnaam") & ""

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Search function - Invalid use of Null

    Quote Originally Posted by Hownice View Post
    ...
    The code I use is:
    Code:
    ...
    
    'this line below is yellow        
    txtBedrijfsnaam.Text = rs1.Fields("fldBedrijfsnaam")
    
    ...
    The fiollowing should be applied to all other lines where you assign recordset fields values to tyour textboxes:
    Code:
    'you can do this (preferable)
    If Not IsNull(rs1.Fields("fldBedrijfsnaam")) Then
        txtBedrijfsnaam.Text = rs1.Fields("fldBedrijfsnaam")
    Else
        txtBedrijfsnaam.Text = "N/A" '<<< this isn't necessary - just showing you what can be done...
    End If
    
    'or this:
    txtBedrijfsnaam.Text = "" & rs1.Fields("fldBedrijfsnaam")

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Search function - Invalid use of Null

    Here's a solution to it: http://www.vbforums.com/showthread.php?t=401834 ...

    Edit:
    Rhino beat me to it
    Last edited by akhileshbc; Apr 24th, 2010 at 09:32 AM. Reason: didn't see Rhino's post

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Location
    Netherlands, Wateringen
    Posts
    24

    Re: Search function - Invalid use of Null

    Quote Originally Posted by RhinoBull View Post
    The fiollowing should be applied to all other lines where you assign recordset fields values to tyour textboxes:
    Code:
    'or this:
    txtBedrijfsnaam.Text = "" & rs1.Fields("fldBedrijfsnaam")
    Hi Rhinobull and others,

    This line dit the trick, now my code works perfect on this part!

    Many thanks

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