Subform Stay on Current Record

Lynn_AccessUser

Registered User.
Local time
Today, 02:09
Joined
Feb 4, 2003
Messages
125
I have a subform where the default view is single form.

On the after update event on my combo boxes I have the following code:

rs = Forms!frmReq!sbfReqItems!txtReqItemID
DoCmd.RunCommand acCmdSaveRecord
Forms!frmReq!sbfReqItems.Requery
Forms!frmReq!sbfReqItems!txtReqItemID.SetFocus
DoCmd.FindRecord rs

When the user changes data in these fields the focus will stay on the current record instead of going back to the first record.

The problem is when the user is adding a new record. There is no value in txtReqItemID (Primary key) because the record has not been saved. As a result, the code breaks because txtReqItemID is null.

If I put in DoCmd.RunCommand acCmdSaveRecord the primary key is created but then it takes me back to the first record instead of staying on the current record.

I can create an if statement to run the rs code when txtReqItemID is not null, but how do I keep the focus on the current record when adding a new record.

Thanks!!!
 
rs = Forms!frmReq!sbfReqItems!txtReqItemID
DoCmd.RunCommand acCmdSaveRecord
Forms!frmReq!sbfReqItems.Requery
Forms!frmReq!sbfReqItems!txtReqItemID.SetFocus
DoCmd.FindRecord rs

The save record command will not take you back to the first record, the requery will.

Have you tried

DoCmd.RunCommand acCmdSaveRecord
rs = Forms!frmReq!sbfReqItems!txtReqItemID
Forms!frmReq!sbfReqItems.Requery
Forms!frmReq!sbfReqItems!txtReqItemID.SetFocus
DoCmd.FindRecord rs

If you are only trying to refresh the data in the combo box
just use:

DoCmd.RunCommand acCmdSaveRecord
Forms!frmReq!sbfReqItems!ComboBoxName.Requery

Dave
 
Last edited:

Users who are viewing this thread

Back
Top Bottom