Can any one help me in the following error.

am connecting database and comparing 3 columns to find the biggest number. the code is executing properly when am compling(i.e. when i compile with F8 key). but at the run time the value am getting is 0. please help me in this regards. the code which i used is

k=0
For i = 0 To 2
If Not (IsNull(rs(i)) Then
If k < Val(rs(i)) Then
k = Val(rs(i))
End If
End If

Next
rs.MoveNext
MsgBox k

It should be rs.Fields(i) instead of rs(i). Also maybe there's some problem with the connection of record set with the database file. Please post the entire code. Use code tags.

Hi,
rs.Fields(i) is same as rs(i) , Whenever accessing a field, u can give empty string for avoiding null field.
Ex

dim iValue as Integer 
iValue = Val ( rs(i) & "" )

instead of

dim iValue as Integer 
iValue = Val ( rs(i) )

then u check the value.
Your code may be

k=0
Dim iValue As Integer ' or Long, Double ur wish
For i = 0 To 2
   iValue = Val (rs (i) & "")
   If k < iValue  Then
       k = iValue
   End If
Next
rs.MoveNext
MsgBox k

If the field is null, then Val(rs(i) & "" ) returns 0

rs.Fields(i) is same as rs(i) ,

Oh, my apologies. I didn't know that.

Oh, my apologies. I didn't know that.

Its ok friend, no problem

Thanks Yaar. the code is working fine

If so, do mark the thread as 'Solved'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.