0

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

3
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Jishnu
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.