Runtime error 2105

randolphoralph

Registered User.
Local time
Today, 11:18
Joined
Aug 4, 2008
Messages
101
On my main form I have the Form On Current event set to Me.AllowAdditions = False to prevent new records from being added when users use the scroll button on the mouse.

In order to add a new record users have to click on a command button. Here is the code when the command button is clicked.

Code:
Private Sub CommandButton_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord acActiveDataObject, , acNewRec
End Sub


I receive a Run-time error '2105': You can't go to the specified record.
When I click on Debug it points to DoCmd.GoToRecord acActiveDataObject, , acNewRec


The funny thing is that the code worked in an older database .mdb, but will not work in the newer .accdb.

Any thoughts?
 
Try:
Code:
Private Sub CommandButton_Click()
 Me.AllowAdditions = True
 If Not Me.NewRecord Then
  DoCmd.GoToRecord acActiveDataObject, , acNewRec
 End If
End Sub
 
I tried it and I am getting the same error and debug.
 
I tried that and it still gives me the error.

I seem to be getting a little closer. Ok I verified I have Allow Additions = Yes under form properties, and get the error using the code below.

Code:
Private Sub Form_Current()
Me.AllowAdditions = False
End Sub
 
Private Sub All_Load_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord acActiveDataObject, , acNewRec
End Sub

When I comment out the Me.AllowAdditions the command button works and adds a new record with no error.

Code:
Private Sub Form_Current()
'Me.AllowAdditions = False
End Sub
 
Private Sub All_Load_Click()
'Me.AllowAdditions = True
DoCmd.GoToRecord acActiveDataObject, , acNewRec
End Sub
 
Have you tried removing the code from the On Current and On Open events and just using the code I posted for the On Click event of the button.
 
bob fitz....you are correct....I set the Allow Addition = No and removed the On Current and used only your code and it worked.

Thank you bob fitz and Catalina!
 
I just realized that the code works, but does not set Me.AllowAdditions = False after the new record is added....so after the first time the command button is clicked users can add new records without having to use the command button.

If possible I would like for the following to happen when the command button is pressed.

1. Allow Record Additions
2. Add a new record
3. Not Allow Record Additions

Each time the command button is pressed it would repeat the same steps
 
Try this line in the forms After Update event:
Me.AllowAdditions = False
 
After I put in Forms After Update event Me.AllowAdditions = False I get runtime error 2105 and the debug points to DoCmd.GoToRecord acActiveDataObject, , acNewRec

That is the issue I was having initially.
 
I have tried Form Current event Me.AllowAdditions = False same error and debug.
 
I found the solution. Using the Form After Insert event Me.AllowAdditions = False with the Form Property Allow Additions = No
 

Users who are viewing this thread

Back
Top Bottom