Solved Update form & remain in the same record (1 Viewer)

Alex Motilal

New member
Local time
Today, 19:15
Joined
Jul 7, 2021
Messages
15
Hi everyone,
I have a form (Single Form) for entering data which has multiple fields. After entering the data, when I click the Update Button, it takes to the first record. I do want the form to remain in the same record.
I need the correct code.
Please some one help.
Thanks
 

Alex Motilal

New member
Local time
Today, 19:15
Joined
Jul 7, 2021
Messages
15
Please post the incorrect code you are using at the moment.

You may just need to replace it with:
Code:
Me.Dirty = False
Thank you. Following is the code at present:

Private Sub cmdSave_Click()
On Error GoTo cmdSave_Click_Err

On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If

Me.Form.Requery

Me.cmdNew.Enabled = True

cmdSave_Click_Exit:
Exit Sub

cmdSave_Click_Err:
MsgBox Error$
Resume cmdSave_Click_Exit

End Sub
 

cheekybuddha

AWF VIP
Local time
Today, 14:45
Joined
Jul 21, 2014
Messages
2,272
Try just:
Code:
Private Sub cmdSave_Click()
On Error GoTo cmdSave_Click_Err

  If Me.Dirty Then Me.Dirty = False
  Me.cmdNew.Enabled = True

cmdSave_Click_Exit:
  Exit Sub

cmdSave_Click_Err:
  MsgBox Err.Description, vbOkOnly, Err.Number
  Resume cmdSave_Click_Exit

End Sub
 

Alex Motilal

New member
Local time
Today, 19:15
Joined
Jul 7, 2021
Messages
15
Thanks a lot. I replaces with Me.Dirty=False & it works fine. Thanks again for your quick solution.
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:45
Joined
Sep 21, 2011
Messages
14,235
Hi everyone,
I have a form (Single Form) for entering data which has multiple fields. After entering the data, when I click the Update Button, it takes to the first record. I do want the form to remain in the same record.
I need the correct code.
Please some one help.
Thanks
If your form is bound, it updates itself, when you move off a record, etc.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:45
Joined
May 7, 2009
Messages
19,233
your Original macro will work acCmdSaveRecord is same as Dirty=False.
you only need to Remove, Requery command.
this will requery your data and you will be tossed to the first record.
 

cheekybuddha

AWF VIP
Local time
Today, 14:45
Joined
Jul 21, 2014
Messages
2,272
your Original macro will work acCmdSaveRecord is same as Dirty=False.
Almost, but it requires the On Error Resume Next in case the record is not dirty, otherwise doesn't it throw an error about not being able to save?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:45
Joined
Sep 21, 2011
Messages
14,235
I think the idea is not to move off the record! :LOL:
I understand that, but to me the O/P seemed to think you had to manually save the record?
Access always seemed strange to me when I started with it, that it did the opposite of what other software did, in the fact that you chose when to update when using those. I got used to the way Access does it though. :)

O/P could have just removed the requery as well, surely?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 14:45
Joined
Sep 12, 2006
Messages
15,638
requerying the form will always reposition the cursor, I think - but you could set the cycle property to "current record" to stop it automatically going to the next record.
 

Users who are viewing this thread

Top Bottom