SetFocus to a Specific Field on a New Record

whdyck

Registered User.
Local time
Today, 14:41
Joined
Aug 8, 2011
Messages
169
I'm using Access 2003.

In a form's AfterUpdate event, I want to know whether the row that was just updated was a new record. I've tried testing the .NewRecord property, but that doesn't work. (Apparently, by the time we're in the AfterUpdate event, it's no longer considered a new record.)

Is there any other way to detect that it was a new record?

Thanks for any help you can give.

Wayne
 
Wayne,
You can't update a new record. You append a new record and use last modified to go to it, or you update an existing record and don't move. If your form is attached to a query and you are requering this will put you at record one. The solution here is you should consider having one form to view the data and this can have a query behind it, and another form to add a new record which is attached to the table. If you know recordsets, that's even better. When you add the new record you grab the primary key number and use the PK and findfirst to get back to it on the view form. Hope that helps.
Michael
 
Wayne,
You can't update a new record. You append a new record and use last modified to go to it, or you update an existing record and don't move. If your form is attached to a query and you are requering this will put you at record one. The solution here is you should consider having one form to view the data and this can have a query behind it, and another form to add a new record which is attached to the table. If you know recordsets, that's even better. When you add the new record you grab the primary key number and use the PK and findfirst to get back to it on the view form. Hope that helps.
Michael

Hi, Michael,

I think I understand what you're saying, but still not quite sure how to implement.

My form is actually a subform that's nested two levels deep. Because the subform needs to talk to the parent forms, I need to requery both the parent and grandparent forms whenever a row is updated in the subform. That's where the problem arises. What I'd really like to see happen is for the focus to return to the very next row in the subform after any type of record update: (1) if it's an update of an existing record, advance the focus to the first field on the next record in the grid, and (2) if it's the saving of a newly-entered row, advance to the first field of a new row.

I'm thinking I need to somehow use a recordset to find the next record after the current one being updated, then make that record current and go to the first field. Not sure what code would get me there.

Thanks.

Wayne
 
I believe the key is to use the two different events:

Before/After Update - Only affects updated records : If they are updating capture the current index location and use the goto command to go to the next one in an afterupdate command (or whenever), actually I think goto next will do it.

Before/after Insert - Only affects new records : If they are adding a new record use the goto new command afterwards
 
I believe the key is to use the two different events:

Before/After Update - Only affects updated records : If they are updating capture the current index location and use the goto command to go to the next one in an afterupdate command (or whenever), actually I think goto next will do it.

Before/after Insert - Only affects new records : If they are adding a new record use the goto new command afterwards

This worked.

Actually, based on your suggestion, I just added the following command to the After Update event and it fixed all:
Code:
DoCmd.GoToRecord , , acNext
Thanks for the help!

Wayne
 

Users who are viewing this thread

Back
Top Bottom