Friday 22 June 2012

3. Move with no records in VBA


Using any of the Move methods (MoveFirst, MoveLast, MoveNext, or MovePrevious) causes anerror if the recordset has no records.


Solution:

Test before using any of the Move methods. Either of these approaches works:
    If Not (rs.BOF And rs.EOF) Then 'There are no records if Beginning-Of-File and End-Of-File are both true.
    If rs.RecordCount <> 0 Then     '100% reliable in DAO, but some ADO recordsets return -1 as the count.





No comments:

Post a Comment