Error 3367 Object already in collection. Cannot append (1 Viewer)

Oludare

New member
Local time
Today, 22:14
Joined
Jan 28, 2021
Messages
24
Hello All,

Please help. Below is my code on click it produced the Error message Error 3367 Object already in collection. Cannot append.

Private Sub cmdSave_Click()

'Dim strNewBordNo As String
'Dim strMsg As String

On Error GoTo Save_Error

'Dim StrBordNo As String
'StrBordNo = Me.txtBordNo

' Moved this code from For_BeforeUpdate tp Save event as part of WP002
'ValidFail = False
'strMsg = ""
'InsertReissueStgData

'Dim ctl As Control
'For Each ctl In Me.Controls
' If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
' If ctl.Tag = "Mandatory" And Nz(ctl.Value, "") = "" Then
' strMsg = strMsg + ctl.Controls(0).Caption & vbTab & ctl.Tag & vbCrLf
' End If
' End If
'Next ctl

'Cheque Populated
'Dim strcheck As String
'strcheck = Nz(Me.cboPaymentMthd, "")

'If Nz(Me.cboPaymentMthd.Value, "") = "Cheq" And Nz(Me.cboPaymentMthd.Value, "") <> "" Then
' For Each ctl In Me.Controls
' If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
' If ctl.Tag = "ChequeMan" And Nz(ctl.Value, "") = "" Then
' strMsg = strMsg + ctl.Controls(0).Caption & vbTab & "Mandatory" & vbCrLf
' End If
' End If
' Next ctl
' Else
' For Each ctl In Me.Controls
' If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
' If ctl.Tag = "BacsMan" And Nz(ctl.Value, "") = "" Then
' strMsg = strMsg + ctl.Controls(0).Caption & vbTab & "Mandatory" & vbCrLf
' End If
' End If
' Next ctl
'End If


'If strMsg <> "" Then 'Cancels out of save if any Mandatory fields are empty
' MsgBox "Please populate below fields" & vbCrLf & vbCrLf & _
' strMsg, vbCritical, "Mandatory Fields"
' Dim Cancel As Boolean
' Cancel = True
' Exit Sub
'Else
'DoCmd.RunCommand acCmdSaveRecord
' Call Insert Data to Reissue Data
' InsertReissueStgData

'End If

Call InsertReissueStgData

cmdSave_Click_Exit:
DoCmd.Close acForm, Me.Name


Exit Sub


Save_Error:

If Err.Number <> 2501 And Err.Number <> 0 And Err.Number <> 30014 Then '30014 Added for WP002
modMessageHelper.ShowErrorMessage Err.Description, "frmInsertReissueRecord.cmdSave_Click", Err.Number
Else
DoCmd.Close acForm, Me.Name 'Added for WP002
End If
Exit Sub


'DoCmd.Close acForm, Me.Name

End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:14
Joined
May 21, 2018
Messages
4,879
looking at this my first guess is not in the code by in the code you are not showing
InsertReissueStgData

I expect this to be an ADO connection issue, but just guessing without seeing it.
 

Isaac

Lifelong Learner
Local time
Today, 14:14
Joined
Mar 14, 2017
Messages
4,693
Please properly indent your code to make it readable
Please put your code in code tags (the </> icon)

Please explain why almost the whole code is commented out.
Please explain which line of code is highlighted when you click Debug after it errs

Then please post the question
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:14
Joined
Sep 21, 2011
Messages
7,989
Can't see the wood for the trees :)
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 22:14
Joined
Jul 9, 2003
Messages
12,769
looking at this my first guess is not in the code by in the code you are not showing
InsertReissueStgData

I agree with MajP.

To confirm comment out the line with "InsertReissueStgData" and run the code again and see if you still get the error.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:14
Joined
Sep 21, 2011
Messages
7,989
I agree with MajP.

To confirm comment out the line with "InsertReissueStgData" and run the code again and see if you still get the error.
If they do that, all that is left is to close the form.? :)
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 22:14
Joined
Jul 9, 2003
Messages
12,769
If they do that, all that is left is to close the form.?

I haven't really looked at the code closely, although I can't see anything obviously wrong with it.

I adopt a process of elimination, this will certainly demonstrate where the error lies...
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:14
Joined
Sep 21, 2011
Messages
7,989
I realise that Tony, divide and conquer :), it is just that there is not much to it, if you removed all the commented lines. :) again as I said 'Hard to see the wood for the trees' :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:14
Joined
Sep 21, 2011
Messages
7,989
Thank you for your advice. I have since fixed the issue.
Well for the benefit of others, please post your solution.
You never know, it might help someone else later?
After all that is what this site is about?
 

Users who are viewing this thread

Top Bottom