ACC: Type Mismatch When Comparing Bookmarks

Last reviewed: August 28, 1997
Article ID: Q152548
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you compare a recordset's bookmark with a Variant or String variable, you may receive the following error message:

   Run-time error '13:'
   Type Mismatch

This error message can also occur when you compare a recordset's bookmark to the RecordsetClone of, for example, a form's record source.

RESOLUTION

Use the StrComp() function to compare a Variant or String variable to a bookmark, or to compare a bookmark against a bookmark. The third argument for the StrComp() function must be set to a value of 0 (zero).

For example, the following code tests to see if a form is displaying its last record by first cloning the record source of the form, moving to the last record within the cloned recordset, and then testing to see if the last record within the cloned recordset matches the record currently displayed on the form:

   Dim RS As Recordset
   Set RS = Me.RecordsetClone
   RS.MoveLast
   If StrComp(Me.Bookmark, RS.Bookmark, 0) = 0 Then
      MsgBox "Form is displaying the last record."
   End If

MORE INFORMATION

Online Help for the Bookmark Property contains the following subheading:

   'Settings and Return Values.'

The information under this subheading reads as follows:

   The setting or returned value is a string expression or variant
   expression that evaluates to a valid bookmark. (Data type is Variant
   array of Byte data.)

Despite the information in Help, if a bookmark is compared against a variable of data type Variant or String, or compared to another bookmark while using a comparison operator (such as an equal sign) in Visual Basic for Applications, the procedure fails, generating the error message defined in the SYMPTOMS section.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Enter the following into the OnCurrent event of the Customers form:

          Dim RS As Recordset
          Set RS = Me.RecordsetClone
          RS.MoveLast
          If Me.Bookmark = RS.Bookmark Then
    
             MsgBox "Form is displaying the last record."
          End If
    
    

  3. Click Form on the View menu. Note that Microsoft Access displays the following error message:

          Run-time error '13:'
          Type mismatch
    

  4. Click the Debug button. Note that Microsoft Access highlights the line of code where the type mismatch occurs. The line of code is:

          If Me.Bookmark = RS.Bookmark Then
    

REFERENCES

For more information about the StrComp() function, search the Help Index for "StrComp Function," or ask the Microsoft Access 97 Office Assistant.

For more information about the Bookmark Property, search the Help Index for "Bookmark Property," or ask the Microsoft Access 97 Office Assistant.

Keywords          : JetRS kberrmsg kbprg PgmObj
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbdocerr


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.