Does DataSISPEDA.Recordset.Fields("DocID").Value only contain whole numbers? If it does, the most sensible thing to do would be convert the field in the database to a Long datatype.

That way you avoid all the overhead of using Trim (which is very slow) and Val which actually returns a Double.

Then you would declare max as a Long and your code would look like
VB Code:
  1. Do While Not DataSISPEDA.Recordset.EOF
  2.        
  3.     If max <= DataSISPEDA.Recordset.Fields("DocID").Value Then
  4.         max = DataSISPEDA.Recordset.Fields("DocID").Value
  5.         DataSISPEDA.Recordset.MoveNext
  6.     Else
  7.         DataSISPEDA.Recordset.MoveNext
  8.     End If
  9.  
  10. Loop