Knowledge Base

PRB: Comparing Bookmarks Generates Type Mismatch Error

Article ID: 129933

Article Last Modified on 12/9/2003


APPLIES TO


This article was previously published under Q129933

SYMPTOMS

If you attempt to use the Bookmark property in a compare operation with another bookmark, you receive the following error if the bookmarks are not first stored in string variables:
Run-time error 13 - Type Mismatch

CAUSE

This is by design. Bookmarks in Visual Basic version 4.0 are stored in byte arrays. Arrays cannot be directly compared to each other.

RESOLUTION

Before accessing the Bookmark property, copy the bookmark values to string variables, and make all comparisons using the string variables. The following code compares two bookmarks correctly.

Step-by-Step Example

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. In the click event for Form1, place the following code:
       Private Sub Form_Click()
          Dim Db As Database
          Dim Rs As Recordset
          Dim Cs As Recordset
          Dim sBook1 as String
          Dim sBook2 as String
    
          Set Db = DBEngine.Workspaces(0).OpenDatabase("biblio.mdb")
          Set Rs = Db.OpenRecordset("authors", dbOpenDynaset)
          Set Cs = Rs.Clone()
    
          sBook1 = Rs.Bookmark
          sBook2 = Cs.Bookmark
    
          If sBook1 = sBook2 Then
             MsgBox "Match"
          Else
             MsgBox "No Match"
          End If
       End Sub
    						
  3. Run the program by pressing the F5 key.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Problem

Use the above example, but replace the code in the Form_Click procedure with this code:
   Private Sub Form_Click()
      Dim Db As Database
      Dim Rs As Recordset
      Dim Cs As Recordset

      Set Db = DBEngine.Workspaces(0).OpenDatabase("biblio.mdb")
      Set Rs = Db.OpenRecordset("authors", dbOpenDynaset)
      Set Cs = Rs.Clone()

      If Rs.Bookmark = Cs.Bookmark Then  'Error 13 - Type Mismatch
         MsgBox "Match"
      else
         MsgBox "No Match"
      End If
   End Sub
				

Additional query words: 4.00 vb4win vb4all

Keywords: kbprb kbcode KB129933