“Add A New Record” function is not working

access2010

Registered User.
Local time
Yesterday, 19:00
Joined
Dec 26, 2009
Messages
1,139
I would appreciate some help with the adding of new records to this form
@On Click = Event Procedure

= = =
Private Sub cmdAddNewRecord_Click()

On Error GoTo Err_cmdAddNewRecord_Click

' Save any current changes to the record

DoCmd.RunCommand acCmdSaveRecord

' Attempt to add a new record

DoCmd.GoToRecord , , acNewRec

Exit_cmdAddNewRecord_Click:

Exit Sub

Err_cmdAddNewRecord_Click:

MsgBox "Error " & Err.Number & ": " & Err.Description

Resume Exit_cmdAddNewRecord_Click

End Sub

= = =
Error Message
Stock Name and Stock Symbol already exists on the investments01_Tbl => OK

= = =
You can’t go to the specified record

Thank you Barbara
 
Thank you DHookom, for your suggestion.

We have been using the code in this database since 2010 without any issue until now, specifically, “ONLY in THIS FORM”.

We have tried many other codes without success and would appreciate your assistance with this problem.
 
You don't need the save record command at all. ACCESS saves records automatically. If you can't add records, then check the record source and make sure it allows new records to be added. If you still can't add records then check the form properties. Someone changed something.
 
The error message you posted doesn't look like it comes from Access. Is it generated by your own application? Seems to be pretty self explanatory.

No "add new record" button should be saving the current record. You haven't placed any data into it. Your validation should fail.

If the button is actually a "save" button (then it is misnamed) that you want to advance to a new, empty record AFTER the save, then the code makes sense but you STILL need to validate the current record in the form's BeforeUpdate event.
 
You don't need the save record command at all. ACCESS saves records automatically. If you can't add records, then check the record source and make sure it allows new records to be added. If you still can't add records then check the form properties. Someone changed something.
Thank you, Larry for your comments.
I created a new form with the same code and experienced no problems.
Only THIS form is causing an error.

We have been using the same code since before 2010, so your suggestion on how to correct this problem would be appreciated.
Barbara
 
Thank you, Larry for your comments.
I created a new form with the same code and experienced no problems.
Only THIS form is causing an error.

We have been using the same code since before 2010, so your suggestion on how to correct this problem would be appreciated.
Barbara
If the record source on the form allows new records to be entered but the form does not, then something has been changed on the old form. Check the forms Allow Additions and Allow Edits property settings:
1756066527054.png

to make sure the form allows new records. I am glad the new form works for you now.
 
What is exact name of the table you are adding records to? The table refereced in the error message.
 

Users who are viewing this thread

Back
Top Bottom