I am new to MS Access and can't find the problem here. My code worked from the beginning, but now I keep getting this error when trying to delete a data record. Here is my code:
Private Sub cmdLoeschen_Click()
If MsgBoxYesNo(CancelOrderConfirmPrompt) Then
If [Prozessspezifikationen].Delete(Me![Prozessspezifikation ID]) Then
MsgBoxOKOnly CancelOrderSuccess
eh.TryToGoToRecord acNewRec
Else
MsgBoxOKOnly CancelOrderFailure
End If
End If
End Sub
The Delete function used:
Function Delete(ProzessspezifikationID As Long) As Boolean
Dim rsw As New RecordsetWrapper
If rsw.OpenRecordset("Prozessspezifikationen", "[Prozessspezifikation ID] = " & ProzessspezifikationID) Then
Delete = rsw.Delete
End If
End Function
where:
[Prozessspezifikation ID]
is the primary key in the underlying table[Prozessspezifikationen]
is an autoincrement long integer- the table contains several foreign keys
I use the following query to get the data needed in my Formular:
SELECT Prozessspezifikationen.*, Products.Bezeichnung, Products.ZeichnungsNr
FROM Products
INNER JOIN Prozessspezifikationen
ON Products.ArtikelID = Prozessspezifikationen.ArtikelID;
As I am new to MS Access and it doesn't seem to be a syntax error, I am a bit lost.
RecordsetWrapper (excerpt):
Option Compare Database
Option Explicit
Private m_rs As DAO.Recordset2
Public Function GetRecordsetClone(rs As DAO.Recordset2) As DAO.Recordset2
If Not m_rs Is Nothing Then
Debug.Assert False
Else
Set m_rs = rs.Clone
Set GetRecordsetClone = m_rs
End If
End Function
OpenRecordset Function
Public Function OpenRecordset(Domain As String, _
Optional Criteria As String = "1=1", _
Optional OrderBy As String, _
Optional RecordsetType As DAO.RecordsetTypeEnum = dbOpenDynaset, _
Optional RecordsetOptions As DAO.RecordsetOptionEnum _
) As Boolean
If Not m_rs Is Nothing Then
CloseRecordset
End If
Dim strSQL As String
strSQL = "SELECT * FROM [" & Domain & "] WHERE " & Criteria
If OrderBy <> "" Then
strSQL = strSQL & " ORDER BY " & OrderBy
End If
On Error GoTo ErrorHandler
Set m_rs = CurrentDb.OpenRecordset(strSQL, RecordsetType, RecordsetOptions)
OpenRecordset = True
Done:
Exit Function
ErrorHandler:
Debug.Assert m_rs Is Nothing
If eh.LogError("RecordsetWrapper.OpenRecordset", "strSQL = " & Chr(34) & strSQL & Chr(34)) Then Resume
End Function
Delete Function
Public Function Delete() As Boolean
On Error GoTo ErrorHandler
m_rs.Delete
Delete = True
Done:
Exit Function
ErrorHandler:
If eh.LogError("RecordsetWrapper.Delete") Then Resume
End Function
CloseRecordset Function
Public Function CloseRecordset() As Boolean
On Error GoTo ErrorHandler
m_rs.Close
CloseRecordset = True
Done:
Set m_rs = Nothing
Exit Function
ErrorHandler:
If eh.LogError("RecordsetWrapper.CloseRecordset") Then Resume
End Function
Public Property Get Recordset() As DAO.Recordset2
Set Recordset = m_rs
End Property
Private Sub Class_Terminate()
If Not m_rs Is Nothing Then
m_rs.Close
Set m_rs = Nothing
End If
End Sub
I hope you can help me. I can give you more information if needed.