Solved Error 3022 when Saving and Closing form (1 Viewer)

Zydeceltico

Registered User.
Local time
Today, 11:56
Joined
Dec 5, 2017
Messages
843
Hi All -

I have a table tblCoils. Primary key (autonumber) is CoilNumber_PK. Main field is CoilNumber which is indexed, required, and Yes (No Duplicates).

On my main menu I have a button titled "Coils Add/Edit." Clicking that button opens frmCoils which has two buttons of importance: one to "Find Coil" and one to "Add New Coil."

Clicking "Find Coil" opens frmCoilStatus with this code:
Code:
Private Sub cmdOpenCoilDetails_Click()
    DoCmd.Close 'closes frmCoils
    DoCmd.OpenForm "frmCoilStatus"
    Forms![frmCoilStatus].[cmdUndoCoilStatus].Enabled = False
    Forms![frmCoilStatus].[cmdSaveCoilStatus].Enabled = False
End Sub

When frmCoilStatus opens it goes to the first record in the table which is fine. The form has two enabled buttons one of which is "Add Coil" because I would like to allow the user to enter a new coil from here without returning to the previous form. Clicking the "Add Coil" button does clear all fields in the form and moves to a new record.

The click event for the "Add Coil" button has this code:
Code:
Private Sub cmdAddCoil_Click()
On Error GoTo cmdAddCoil_Click_Err

On Error Resume Next
    DoCmd.GoToRecord , "", acNewRec
    Forms![frmCoilStatus]![cmdSaveCoilStatus].Enabled = True
    Forms![frmCoilStatus]![cmdUndoCoilStatus].Enabled = True
   
cmdAddCoil_Click_Exit:
    Exit Sub

cmdAddCoil_Click_Err:
    MsgBox Error$
    Resume cmdAddCoil_Click_Exit

End Sub

The user enters a new coil number in txtCoilNumber and can then click a "Save and Close" button.
The code for the "Save and Close" button is this:
Code:
Private Sub cmdSaveCoilStatus_Click()

        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.Close

End Sub

When I enter a new coil number in txtCoilNumber and click the"Save and Close" button I get Runtime Error 3022 saying "The changes you requested......because they would create duplicate values, etc.......Change the data in the field..................or redefine the inex to permit duplicate entries........."

But I am not entering duplicate values and I can from the record selector at the bottom of the form that I am definitely on a new record.

And ..........if I DO NOT enter a coil number and click "Save and Close" I get runtime error 3314 which recognizes that CoilNumber is required and says I must enter a value.

Thoughts?
 

Attachments

  • QCDB Coil Error 3022.zip
    277.2 KB · Views: 366
Last edited:

Zydeceltico

Registered User.
Local time
Today, 11:56
Joined
Dec 5, 2017
Messages
843
I just noticed that if I go through the process described above to get to adding a new coil on frmCoilStatus and I don't add anything in any field and click "Save and Close" the form closes without any warning whatsoever including saying that CoilNumber is required.

That's not good.
 

Zydeceltico

Registered User.
Local time
Today, 11:56
Joined
Dec 5, 2017
Messages
843
Well - I think I fixed my 3022 error issue......I had messed up the indexes on tblCoils - - but now.............I'll start a new post. :)
 

Zydeceltico

Registered User.
Local time
Today, 11:56
Joined
Dec 5, 2017
Messages
843
I was wrong - not fixed.

Here's a further updated db.
 

Attachments

  • QCDB Coil Error 3022.zip
    283.9 KB · Views: 339

Zydeceltico

Registered User.
Local time
Today, 11:56
Joined
Dec 5, 2017
Messages
843
I figured it out. Long story but I corrupted my original primary key autonumber field. Made a new field autonumber then made it primary key and now it works as expected.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:56
Joined
Feb 19, 2013
Messages
16,553
at least one's got to be wrong or there's no discussion....
 

Users who are viewing this thread

Top Bottom