Add new record

W

Warren Siu

My form set Allowadditions to False and also do it on Current event to
prevent adding record in an uncontrollable way. Users have to use the Add New
buttom to add new record. My code is
Private Sub add_Click()
Me.AllowAdditions = True
Me.Refresh
DoCmd.GoToRecord , , acNewRec
Me![TI Ref] = DMax("[TI Ref]+1", "Inspection Record")
End Sub
But error "2105", "You can't go to the specified record" appear.
Why and how to get around?
Thanks
 
J

June7 via AccessMonster.com

Do you have the form AllowEdits property set to Yes? Not sure if that will
make a difference. But I have three forms that I also set the AllowAdditions
property in code. All have the AllowEdits set to Yes. Two of them work but
the third is not working right, it involves a table with an autonumber. Do
you have autonumber field in your table?

Warren said:
My form set Allowadditions to False and also do it on Current event to
prevent adding record in an uncontrollable way. Users have to use the Add New
buttom to add new record. My code is
Private Sub add_Click()
Me.AllowAdditions = True
Me.Refresh
DoCmd.GoToRecord , , acNewRec
Me![TI Ref] = DMax("[TI Ref]+1", "Inspection Record")
End Sub
But error "2105", "You can't go to the specified record" appear.
Why and how to get around?
Thanks
 
W

Warren Siu

June7
Thanks for your response.
I've also set the AllowEdits and AllowDelete to false in my form and the
underlying table with no autonumber field.
Any suggestion?

June7 via AccessMonster.com said:
Do you have the form AllowEdits property set to Yes? Not sure if that will
make a difference. But I have three forms that I also set the AllowAdditions
property in code. All have the AllowEdits set to Yes. Two of them work but
the third is not working right, it involves a table with an autonumber. Do
you have autonumber field in your table?

Warren said:
My form set Allowadditions to False and also do it on Current event to
prevent adding record in an uncontrollable way. Users have to use the Add New
buttom to add new record. My code is
Private Sub add_Click()
Me.AllowAdditions = True
Me.Refresh
DoCmd.GoToRecord , , acNewRec
Me![TI Ref] = DMax("[TI Ref]+1", "Inspection Record")
End Sub
But error "2105", "You can't go to the specified record" appear.
Why and how to get around?
Thanks
 
K

Ken Snell MVP

Your Form_Current event immediately sets the AllowAdditions property back to
False when you try to move to a new record. Change your Form_Current
procedure to test for a new record, and do not set AllowAdditions to False
in that situation:

Private Sub Form_Current()
Me.AllowAdditions = Me.NewRecord
End Sub
 
W

Warren Siu

Dear Ken Snell MVP
It work.
Thank very much.

Ken Snell MVP said:
Your Form_Current event immediately sets the AllowAdditions property back to
False when you try to move to a new record. Change your Form_Current
procedure to test for a new record, and do not set AllowAdditions to False
in that situation:

Private Sub Form_Current()
Me.AllowAdditions = Me.NewRecord
End Sub
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Warren Siu said:
My form set Allowadditions to False and also do it on Current event to
prevent adding record in an uncontrollable way. Users have to use the Add
New
buttom to add new record. My code is
Private Sub add_Click()
Me.AllowAdditions = True
Me.Refresh
DoCmd.GoToRecord , , acNewRec
Me![TI Ref] = DMax("[TI Ref]+1", "Inspection Record")
End Sub
But error "2105", "You can't go to the specified record" appear.
Why and how to get around?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top