I have a form with RecordSource "tblInvNew", which is empty and is identical in structure to table "tblInv". All of the controls in the form, where applicable, are bound to the same table names as are defined in the two tables. The user has the option of either saving or canceling. When the user opts to SAVE, I've attempted to update the table "tblInv" thus:
Code:
Private Sub lblSAVE_Click()
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' Okay, everything required to enter a new record has been satisfied, copy fields to our main table.
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
If strMode = "New" Then
CurrentDb.Execute "INSERT INTO tblInv SELECT * FROM tblInvNew", dbFailOnError
CurrentDb.Execute "DELETE * FROM tblInvNew", dbFailOnError
End If
DoCmd.Close acForm, "frmItemDescriptor", acSaveYes
End Sub
I get error 3022 and I've not been able to determine why. So, I changed the code to below to run in debug looking for what might be the culprit, but it too gets the 3022 error when I execute the ".Update" statement.
Code:
Private Sub lblSAVE_Click()
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' Okay, everything required to enter a new record has been satisfied, copy fields to our main table.
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Dim rsSav As DAO.Recordset
Dim strTemp As String
If strMode = "New" Then 'Current RecordSet is QInvNew
Set rsSav = DBEngine(0)(0).OpenRecordset("tblInv")
With rsSav
.AddNew
!Description = Me.tbItemDescription
!Keep = Me.chkKeep
!Donate = Me.chkDonate
!Sold = Me.chkSold
!Sell = Me.chkSell
!Comment = Me.tbComment
!Im1 = Me.tbImage1
!Im2 = Me.tbImage2
!Im3 = Me.tbImage3
!Im4 = Me.tbImage4
!Im5 = Me.tbImage5
!Im6 = Me.tbImage6
.Update
End With
rsSav.Close
Set rsSav = Nothing
CurrentDb.Execute "DELETE * FROM tblInvNew", dbFailOnError
End If
DoCmd.Close acForm, "frmItemDescriptor", acSaveYes
End Sub
The 3022 error suggests some sort of duplicate condition, but that makes no sense to me simply adding a record. And yes, both tables are indexed on primary autonumber keys. Any ideas what's causing the conflict?