Thank you for reaching out to the Microsoft Q&A community and sharing your issue in detail.
Based on the code you've posted and description of your error, “Type Mismatch” error may happen when the database provider doesn’t fully support the RecordCount property for the specific cursor type you’re using. In many cases, RecordCount might return -1, which usually works with a Long variable. However, the fact that you’re seeing this error specifically on the RecordCount line, especially after a MoveLast, suggests that the combination of provider and cursor type may not be compatible with this property at all.
Typically, this issue arises when the recordset is opened with the default cursor settings, which may not support certain operations like MoveLast or provide a reliable record count. For example, a forward-only cursor doesn’t allow moving backwards or jumping to the last record, and this could lead to unexpected errors.
To help ensure that RecordCount returns a valid number, you might consider explicitly setting the cursor to a client-side static cursor before opening your recordset. This approach is often more reliable, as it allows ADO to manage the records locally and provide accurate counts.
rsRecordset.CursorLocation = adUseClient
rsRecordset.CursorType = adOpenStatic
rsRecordset.Open "SELECT * FROM YourTable", YourConnection
With these settings, RecordCount is typically available immediately after opening the recordset. Even so, it’s still a good idea to write your code defensively, just in case the environment behaves differently than expected. Your use of MoveLast makes sense for navigating to the end of the recordset, and with a client-side cursor.
Sub MoveToLastRecord(lRecCounter As Long, rsRecordset As ADODB.Recordset, _ objObject As Object, blnAddMode As Boolean)
I hope this may help clarify the situation and give you a path forward. I truly appreciate your patience and understanding.
Please understand that our initial response may not always resolve the issue immediately. However, with your further updates and more detailed information, we can work together to find a resolution.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.