Use Recordset.Supports() Method for Robust Code

Use Recordset.Supports() Method for Robust Code

You can use Supports() method of ADODB.Recordset object to write robust code. This method takes in a enum parameter and returns a boolean value which can be used to determine whether a specified Recordset object supports particular functionality.

The enum constants that can be passed to this method to check if recordset supports a particular functionality are adAddNew, adApproxPosition, adBookmark, adDelete, adFind, adHoldRecords, adMovePrevious, adNotify, adResync, adUpdate, and adUpdateBatch.

For example:
(a)You can use AddNew() method only when the recordset supports addition of new records. This can be easily checked using the Supports method:

 If (oRecordset.Supports(adAddNew)) Then' recordset supports addition of new recordEnd If

(b)Another example would be in case of forward-only recordsets where backward movement may generate an error or decrease the performance of your application. Normally you should receive an error if you call MoveFirst() on forward-only recordsets but some providers may allow this, and implement it by resubmitting the command. For example, the OLEDB driver for ODBC allows MoveFirst() when talking to SQL Server, even though the Supports(adMovePrevious) method returns False. In all such cases you should use Supports(adMovePrevious) otherwise it can degrade the performance if the command that has been resubmitted takes a lot of time.

 If (oRecordset.Supports(adMovePrevious)) Then    ' recordset allows backward movement so move to the first record    oRecordset.MoveFirstEnd If
See also  How to Avoid Money Transfer Scams  

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist