[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2009-02-18
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

Question by:9XqUwH3S
LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 2000 total points
ID: 23674645
MainID is autoNumber  Number data type

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

Author Closing Comment

ID: 31548457
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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question