Runtime error 2105 (1 Viewer)

randolphoralph

Registered User.
Local time
Yesterday, 23:21
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?
 

bob fitz

AWF VIP
Local time
Today, 05:21
Joined
May 23, 2011
Messages
4,721
Try:
Code:
Private Sub CommandButton_Click()
 Me.AllowAdditions = True
 If Not Me.NewRecord Then
  DoCmd.GoToRecord acActiveDataObject, , acNewRec
 End If
End Sub
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
I tried it and I am getting the same error and debug.
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
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
 

bob fitz

AWF VIP
Local time
Today, 05:21
Joined
May 23, 2011
Messages
4,721
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.
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
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!
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
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
 

bob fitz

AWF VIP
Local time
Today, 05:21
Joined
May 23, 2011
Messages
4,721
Try this line in the forms After Update event:
Me.AllowAdditions = False
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
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.
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
I have tried Form Current event Me.AllowAdditions = False same error and debug.
 

randolphoralph

Registered User.
Local time
Yesterday, 23:21
Joined
Aug 4, 2008
Messages
101
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

Top Bottom