Friday 22 June 2012

7. FindFirst / Seek without testing NoMatch in VBA


If you use Seek or one of the Find methods (FindFirst, FindLast, FindNext, FindPrevious), and do not test NoMatch, your code will appear to work until you strike a case where the find failed.


Solution:

Always test for NoMatch after using Seek or a Find method. Example:
    rs.FindFirst "City = ""New York"""
    If Not rs.NoMatch Then
        'It's okay to keep processing.
    End If





No comments:

Post a Comment