|
-
Apr 24th, 2010, 09:16 AM
#1
Thread Starter
Junior Member
[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
-
Apr 24th, 2010, 09:23 AM
#2
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,...
-
Apr 24th, 2010, 09:29 AM
#3
New Member
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") & ""
-
Apr 24th, 2010, 09:30 AM
#4
Re: Search function - Invalid use of Null
 Originally Posted by Hownice
...
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")
-
Apr 24th, 2010, 09:31 AM
#5
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,...
-
Apr 24th, 2010, 11:04 AM
#6
Thread Starter
Junior Member
Re: Search function - Invalid use of Null
 Originally Posted by RhinoBull
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|