9XqUwH3S
asked on
Run-time error '3664' Datatype mismatch in criteria expression
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.
2.JPG
3.JPG
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.AddNew
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.Edit
rst![Value] = Me![MainID]
rst.Update ' Update the recordset.
End If
rst.Close ' Close the recordset.
End Sub
1.JPG2.JPG
3.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again.
I accidently pressed 'no' on the "Was this helpful?" question. Let me know if you need me to change that, somehow.