0
votes

First post so hoping this makes some sense. I’m adding data to tables from unbound text boxes using a command button and the .AddNew method. The form itself is still bound at this point. FYI, I’m using unbound boxes as the UI needed for junction tbls was not an option. I’m able to add the data to the tables without a problem. The issue is that after adding a record, the form’s current record stays on the same record as before the addition but I want it to be on the new record. I’m using “rst.Bookmark = rst.LastModified” to set the cursor to the new record in the table and seems to work as I can return values for the new record ... but this does not affect the form. I’ve tried working with “Requery” and “CurrentRecord” but neither resolves the issue.

In summary, after adding a new record to a table I want the form’s current record to reference this new record. For example, if I am on record 12 in the form and add a new record bringing the total records to 25 -- I want the form to be on record "25 of 25" not on "12 of 25". Can you tell me how to do this? Thanks for your help!

    With rst

    .AddNew
        !Event = Forms!MainForm!Event
        !DonorName = Forms!MainForm!DonorName
        !EnvNo = Forms!MainForm!EnvNo
    .Update

    .MoveLast
    .MoveFirst

  End With

rst.Bookmark = rst.LastModified

''' Record count total - show on form - confirmed/same as Access Navigation display
Forms!MainForm!txtTotalRec.Value = rst.RecordCount

''' Current Record - show on form - confirmed/same as Access Navigation display
lngCurrent = Forms!MainForm.CurrentRecord
Forms!MainForm!txtCurrRec.Value = lngCurrent
2
how about simple goto last record? DoCmd.GoToRecord acActiveDataObject, , acLastKrish
Great, that's what I was missing - if you would like to post as an answer will gladly accept. This took me to the next to last record added so I inserted 'Forms!MainForm.Requery' before it and then it went to last record - thanks!B.Cap

2 Answers

0
votes

as per your trial. simply perform a DoCmd.GoToRecord acActiveDataObject, , acLast after a me.requery to update the recordset.

0
votes

it should work, because the addnew method does not require movelast action. you can try refreshing the form with set me.recordset = me.recordset