Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA in Access: How does DoCmd.RunCommand acCmdSaveRecord work?

Tags:

vba

ms-access

I use

DoCmd.RunCommand acCmdSaveRecord

to save but Im not sure how this actually works. Does it save every unsaved change? Or does it save everything no matter if it was changed or not? Or does it only save the current form? Whats about releated unsaved changes in other forms? Or does it function in any other way? Is there any offical documentation to this function?

like image 441
Gener4tor Avatar asked Oct 17 '25 13:10

Gener4tor


1 Answers

It saves the current record of the active form. It is the same as clicking on the record selector.

If the current record is not currently being edited (not "Dirty"), then nothing happens.

If you want better control, especially when dealing with subforms, I suggest to use the Form.Dirty property instead. With this you can explicitly address the form you want to save.

To save the current record in a form module (only save when needed):

If Me.Dirty Then
    Me.Dirty = False
End If

To save the record in any form

With Forms!myForm
    If .Dirty Then
        .Dirty = False
    End If
End With

Or a subform

Forms!mainForm!SubFormControl.Form.Dirty = False

This is much clearer and better IMO. I have stopped using DoCmd.RunCommand acCmdSaveRecord completely.

like image 147
Andre Avatar answered Oct 19 '25 03:10

Andre