Keep the record current after inserting a new record in form










0















I have a form based on a table but I also have some extra options on the same form. I want to keep the record selected after insert so I can set some other options in another table. I tried doing this with VBA After Insert but the form blanks out after that subroutine has ended.



Private Sub Form_AfterInsert()
DoCmd.GoToRecord , , acLast
End Sub


I know my gotorecord works because I can run it manually and it does select the last record. The problem is that there is a form clear that runs after the "AfterInsert". How do I stop it?










share|improve this question






















  • Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

    – Erik von Asmuth
    Nov 14 '18 at 8:32











  • It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

    – HackSlash
    Nov 14 '18 at 19:11















0















I have a form based on a table but I also have some extra options on the same form. I want to keep the record selected after insert so I can set some other options in another table. I tried doing this with VBA After Insert but the form blanks out after that subroutine has ended.



Private Sub Form_AfterInsert()
DoCmd.GoToRecord , , acLast
End Sub


I know my gotorecord works because I can run it manually and it does select the last record. The problem is that there is a form clear that runs after the "AfterInsert". How do I stop it?










share|improve this question






















  • Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

    – Erik von Asmuth
    Nov 14 '18 at 8:32











  • It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

    – HackSlash
    Nov 14 '18 at 19:11













0












0








0








I have a form based on a table but I also have some extra options on the same form. I want to keep the record selected after insert so I can set some other options in another table. I tried doing this with VBA After Insert but the form blanks out after that subroutine has ended.



Private Sub Form_AfterInsert()
DoCmd.GoToRecord , , acLast
End Sub


I know my gotorecord works because I can run it manually and it does select the last record. The problem is that there is a form clear that runs after the "AfterInsert". How do I stop it?










share|improve this question














I have a form based on a table but I also have some extra options on the same form. I want to keep the record selected after insert so I can set some other options in another table. I tried doing this with VBA After Insert but the form blanks out after that subroutine has ended.



Private Sub Form_AfterInsert()
DoCmd.GoToRecord , , acLast
End Sub


I know my gotorecord works because I can run it manually and it does select the last record. The problem is that there is a form clear that runs after the "AfterInsert". How do I stop it?







vba ms-access






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 20:53









HackSlashHackSlash

8731416




8731416












  • Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

    – Erik von Asmuth
    Nov 14 '18 at 8:32











  • It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

    – HackSlash
    Nov 14 '18 at 19:11

















  • Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

    – Erik von Asmuth
    Nov 14 '18 at 8:32











  • It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

    – HackSlash
    Nov 14 '18 at 19:11
















Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

– Erik von Asmuth
Nov 14 '18 at 8:32





Please specify how you're doing the insert. By default, when inserting a record, Access doesn't move the selected record at all.

– Erik von Asmuth
Nov 14 '18 at 8:32













It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

– HackSlash
Nov 14 '18 at 19:11





It's a form for a user to type data in to fields. When you press ENTER to complete the record it moves to a new blank record. This makes sense if you are entering multiple records at once but not if you want to stay on that new record.

– HackSlash
Nov 14 '18 at 19:11












2 Answers
2






active

oldest

votes


















1














The property that controls this is the Form.Cycle property.



Set that to Current Record (1) and pressing enter or tab on the last field will move you back to the first field again.



Do note that enter doesn't save the current record, it's just an alternative for tab. If you want to save the record when leaving the last field, you can use VBA for that.






share|improve this answer























  • This is the correct answer but I had a button with the default property set intercepting the ENTER key.

    – HackSlash
    Nov 14 '18 at 23:03


















0














You are probably using some DoCmd commands to insert the records.



Use the RecordsetClone and nothing will move - and the form will display the new record if a new record can be seen:



Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.AddNew
rs.Fields("First Fieldname").Value = some value
rs.Fields("Second Fieldname").Value = some other value
' etc.
rs.Update
rs.Close


Edit:



To stay on the current record:



Go to the form's Properties, tab Other, set Cycle Property: Current record






share|improve this answer

























  • No, sorry. I am talking about a data entry form.

    – HackSlash
    Nov 14 '18 at 19:12











  • So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

    – Gustav
    Nov 14 '18 at 21:18











  • Yes, that's correct.

    – HackSlash
    Nov 14 '18 at 23:00











  • Then my edited answer should work. I can't think of other options.

    – Gustav
    Nov 15 '18 at 7:56










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289342%2fkeep-the-record-current-after-inserting-a-new-record-in-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The property that controls this is the Form.Cycle property.



Set that to Current Record (1) and pressing enter or tab on the last field will move you back to the first field again.



Do note that enter doesn't save the current record, it's just an alternative for tab. If you want to save the record when leaving the last field, you can use VBA for that.






share|improve this answer























  • This is the correct answer but I had a button with the default property set intercepting the ENTER key.

    – HackSlash
    Nov 14 '18 at 23:03















1














The property that controls this is the Form.Cycle property.



Set that to Current Record (1) and pressing enter or tab on the last field will move you back to the first field again.



Do note that enter doesn't save the current record, it's just an alternative for tab. If you want to save the record when leaving the last field, you can use VBA for that.






share|improve this answer























  • This is the correct answer but I had a button with the default property set intercepting the ENTER key.

    – HackSlash
    Nov 14 '18 at 23:03













1












1








1







The property that controls this is the Form.Cycle property.



Set that to Current Record (1) and pressing enter or tab on the last field will move you back to the first field again.



Do note that enter doesn't save the current record, it's just an alternative for tab. If you want to save the record when leaving the last field, you can use VBA for that.






share|improve this answer













The property that controls this is the Form.Cycle property.



Set that to Current Record (1) and pressing enter or tab on the last field will move you back to the first field again.



Do note that enter doesn't save the current record, it's just an alternative for tab. If you want to save the record when leaving the last field, you can use VBA for that.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 20:12









Erik von AsmuthErik von Asmuth

19.2k62138




19.2k62138












  • This is the correct answer but I had a button with the default property set intercepting the ENTER key.

    – HackSlash
    Nov 14 '18 at 23:03

















  • This is the correct answer but I had a button with the default property set intercepting the ENTER key.

    – HackSlash
    Nov 14 '18 at 23:03
















This is the correct answer but I had a button with the default property set intercepting the ENTER key.

– HackSlash
Nov 14 '18 at 23:03





This is the correct answer but I had a button with the default property set intercepting the ENTER key.

– HackSlash
Nov 14 '18 at 23:03













0














You are probably using some DoCmd commands to insert the records.



Use the RecordsetClone and nothing will move - and the form will display the new record if a new record can be seen:



Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.AddNew
rs.Fields("First Fieldname").Value = some value
rs.Fields("Second Fieldname").Value = some other value
' etc.
rs.Update
rs.Close


Edit:



To stay on the current record:



Go to the form's Properties, tab Other, set Cycle Property: Current record






share|improve this answer

























  • No, sorry. I am talking about a data entry form.

    – HackSlash
    Nov 14 '18 at 19:12











  • So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

    – Gustav
    Nov 14 '18 at 21:18











  • Yes, that's correct.

    – HackSlash
    Nov 14 '18 at 23:00











  • Then my edited answer should work. I can't think of other options.

    – Gustav
    Nov 15 '18 at 7:56















0














You are probably using some DoCmd commands to insert the records.



Use the RecordsetClone and nothing will move - and the form will display the new record if a new record can be seen:



Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.AddNew
rs.Fields("First Fieldname").Value = some value
rs.Fields("Second Fieldname").Value = some other value
' etc.
rs.Update
rs.Close


Edit:



To stay on the current record:



Go to the form's Properties, tab Other, set Cycle Property: Current record






share|improve this answer

























  • No, sorry. I am talking about a data entry form.

    – HackSlash
    Nov 14 '18 at 19:12











  • So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

    – Gustav
    Nov 14 '18 at 21:18











  • Yes, that's correct.

    – HackSlash
    Nov 14 '18 at 23:00











  • Then my edited answer should work. I can't think of other options.

    – Gustav
    Nov 15 '18 at 7:56













0












0








0







You are probably using some DoCmd commands to insert the records.



Use the RecordsetClone and nothing will move - and the form will display the new record if a new record can be seen:



Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.AddNew
rs.Fields("First Fieldname").Value = some value
rs.Fields("Second Fieldname").Value = some other value
' etc.
rs.Update
rs.Close


Edit:



To stay on the current record:



Go to the form's Properties, tab Other, set Cycle Property: Current record






share|improve this answer















You are probably using some DoCmd commands to insert the records.



Use the RecordsetClone and nothing will move - and the form will display the new record if a new record can be seen:



Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.AddNew
rs.Fields("First Fieldname").Value = some value
rs.Fields("Second Fieldname").Value = some other value
' etc.
rs.Update
rs.Close


Edit:



To stay on the current record:



Go to the form's Properties, tab Other, set Cycle Property: Current record







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 21:21

























answered Nov 14 '18 at 9:23









GustavGustav

29.7k51835




29.7k51835












  • No, sorry. I am talking about a data entry form.

    – HackSlash
    Nov 14 '18 at 19:12











  • So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

    – Gustav
    Nov 14 '18 at 21:18











  • Yes, that's correct.

    – HackSlash
    Nov 14 '18 at 23:00











  • Then my edited answer should work. I can't think of other options.

    – Gustav
    Nov 15 '18 at 7:56

















  • No, sorry. I am talking about a data entry form.

    – HackSlash
    Nov 14 '18 at 19:12











  • So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

    – Gustav
    Nov 14 '18 at 21:18











  • Yes, that's correct.

    – HackSlash
    Nov 14 '18 at 23:00











  • Then my edited answer should work. I can't think of other options.

    – Gustav
    Nov 15 '18 at 7:56
















No, sorry. I am talking about a data entry form.

– HackSlash
Nov 14 '18 at 19:12





No, sorry. I am talking about a data entry form.

– HackSlash
Nov 14 '18 at 19:12













So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

– Gustav
Nov 14 '18 at 21:18





So enter manually, press Enter saving the record, current record moves to the next (new) record, but you wish to stay on the record just inserted?

– Gustav
Nov 14 '18 at 21:18













Yes, that's correct.

– HackSlash
Nov 14 '18 at 23:00





Yes, that's correct.

– HackSlash
Nov 14 '18 at 23:00













Then my edited answer should work. I can't think of other options.

– Gustav
Nov 15 '18 at 7:56





Then my edited answer should work. I can't think of other options.

– Gustav
Nov 15 '18 at 7:56

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289342%2fkeep-the-record-current-after-inserting-a-new-record-in-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto