Dear Sir/Madam
Please tell me how can i remove "Invalid use of null" problem . Coding given below

There is no value in rc1.fields(6)

db1.Open "Provider='Microsoft.Jet.OLEDB.4.0';Data Source='" & App.Path & "\tmgmt.mdb';"
st1 = "select * from travel where sno = " & frmtorf.tserial.Text & ";"
            rc1.Open st1, db1, adOpenDynamic, adLockBatchOptimistic
           
            tn1.Text = rc1.Fields(1)
            tn2.Text = rc1.Fields(2)
            tn3.Text = rc1.Fields(3)
            tn4.Text = rc1.Fields(4)
            tn5.Text = rc1.Fields(5)
            [B]cn1.Text = rc1.Fields(6)[/B]
            cn2.Text = rc1.Fields(7)
            cn3.Text = rc1.Fields(8)
            cn4.Text = rc1.Fields(9)
            cn5.Text = rc1.Fields(10)

this error arises if your recordset returns some null values in any of the rows of the recordset.

you need to use


cn1.Text = iif(isnull(rc1.Fields(6)),0,rc1.Fields(6))

that should work for you

Yes debasisdas is correct. Another way to avoid null is concatenate the empty string after the field value
Ex

cn1.Text = rc1.Fields(6) & ""

Instead of writing like this

cn1.Text = rc1.Fields(6)

Write this line as below which will surely avoid null problem:

If IsNull(rc1.Fields(6)) Then
cn1.Text = ""
Else
cn1.Text=rc1.Fields(6)
End If

Please tell me how can i remove "Invalid use of null" problem . Coding given below

Private Sub
On Error goto ErrorFix
' Code
....
....
'
Exit sub
ErrorFix:
Select case err.Number
case 13 ' Invalid use of null
     resume next
case else
     msgbox err.description & " Error #: " & err.Number, vbinformation, "Error"
     resume next
End Select
'
End sub
This article has been dead for over six months. Start a new discussion instead.