We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Run-time error '3664' Datatype mismatch in criteria expression

9XqUwH3S asked
Medium Priority
Last Modified: 2013-11-27
I'm trying to resolve a run-time error '3664' Datatype mismatch in criteria expression error.
I'm wondering if it has anything to do with my tables or if the code is not relevent to Access 2007.

The error is showing to be in the following line:  

rstFrm.FindFirst "[MainID] = '" & rst![Value] & "'" (line 30)

I want my form to open to the recordset that I was viewing before I closed it, the previous session.
Option Compare Database
  Private Sub Form_Load()
           ' Declare database object and recordset objects.
           Dim db As Database, rst As Recordset, rstFrm As Recordset
           ' Set the database object to the current database.
           Set db = CurrentDb
           ' Open the table tblStorage.
           Set rst = db.OpenRecordset("tblStorage")
           ' Set the index for the seek.
           rst.Index = "PrimaryKey"
           ' Look for the MainIDLast record.
           rst.Seek "=", "MainIDLast"
           ' If a match, get the customer ID and take the form to that
           ' record. If no match, do nothing.
           If Not rst.NoMatch Then
               If Not IsNull(rst![Value]) Then
               ' Create clone of the form's record set.
               Set rstFrm = Me.RecordsetClone
               ' Find the matching record.
               rstFrm.FindFirst "[MainID] = '" & rst![Value] & "'"
               If Not rstFrm.NoMatch Then
                   ' Have the form go to that matching record.
                   Me.Bookmark = rstFrm.Bookmark
               End If
                   rstFrm.Close ' Close the recordset rstFrm.
               End If
           End If
           rst.Close ' Close the recordset rst.
End Sub
Private Sub Form_Unload(Cancel As Integer)
 ' The code below finds or creates a record in tblStorage where the
      ' field Variable contains "MainIDLast", and stores the current
      ' MainID in the field called Value.
          ' Declare database object and recordset object.
          Dim db As Database, rst As Recordset
          ' If the current record has no customer ID, do nothing.
          If IsNull(Me![MainID]) Then Exit Sub
          Set db = CurrentDb
          Set rst = db.OpenRecordset("tblStorage")
          rst.Index = "PrimaryKey"
          rst.Seek "=", "MainIDLast"
          ' If not found, create the entry.
          If rst.NoMatch Then
             rst![Variable] = "MainIDLast"
             rst![Value] = Me![MainID]
             rst![Description] = "ID of last edited customer record," _
                                 & Me.Name & "."
             rst.Update ' Update the recordset.
          Else          ' Else save the customer ID of the current record.
             rst![Value] = Me![MainID]
             rst.Update  ' Update the recordset.
          End If
          rst.Close      ' Close the recordset.
End Sub

Open in new window

Watch Question

Top Expert 2016
MainID is autoNumber  Number data type

 rstFrm.FindFirst "[MainID] = " & rst![Value]

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Beutiful. Thank you.

Thanks again.

I accidently pressed 'no' on the "Was this helpful?" question. Let me know if you need me to change that, somehow.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.