I have been using the simple code (below) for a not in list event for years without a problem. In this particular db I keep getting the message "type mismatch runtime error 13" when executing the 'Set tblONIL = DB.OpenRecordset("tblPosition", dbOpenDynaset)' line. It occurs in any Not in List Event on any form, referenced to any table. I have checked all the references, and repaired and recreated it from scratch with the same result. The tables are all linked to a backend which is located in the same directory as the frontend. Does anyone have any idea why this is happening?
Private Sub Position_NotInList(NewData As String, Response As Integer)
Dim NewItem As Integer
Dim DB As Database
Dim tblONIL As Recordset
If IsNull(NewData) Or NewData = " " Then
MsgBox "Select an item from the list or" & Chr(10) & Chr(13) & "cancel adding the record."
Response = DATA_ERRCONTINUE
GoTo ItemListEnd
End If
NewItem = MsgBox("Item Not Found!" & Chr(10) & Chr(13) & "Do You Want to Add This Item?", 36, "NewItem")
If NewItem = 6 Then 'New Item is YES
Set DB = DBEngine.Workspaces(0).Databases(0)
Set tblONIL = DB.OpenRecordset("tblPosition", dbOpenDynaset) ' Change table name
tblONIL.AddNew
tblONIL![Position] = NewData 'Change Field Name
tblONIL.Update
tblONIL.Close
Response = DATA_ERRADDED
Else
Response = DATA_ERRCONTINUE
End If
ItemListEnd:
End Sub
Private Sub Position_NotInList(NewData As String, Response As Integer)
Dim NewItem As Integer
Dim DB As Database
Dim tblONIL As Recordset
If IsNull(NewData) Or NewData = " " Then
MsgBox "Select an item from the list or" & Chr(10) & Chr(13) & "cancel adding the record."
Response = DATA_ERRCONTINUE
GoTo ItemListEnd
End If
NewItem = MsgBox("Item Not Found!" & Chr(10) & Chr(13) & "Do You Want to Add This Item?", 36, "NewItem")
If NewItem = 6 Then 'New Item is YES
Set DB = DBEngine.Workspaces(0).Databases(0)
Set tblONIL = DB.OpenRecordset("tblPosition", dbOpenDynaset) ' Change table name
tblONIL.AddNew
tblONIL![Position] = NewData 'Change Field Name
tblONIL.Update
tblONIL.Close
Response = DATA_ERRADDED
Else
Response = DATA_ERRCONTINUE
End If
ItemListEnd:
End Sub