Save Current Form Record

R

Ryan Langton

Whats an easy way to save the current record displayed on a form?

I have buttons that perform UPDATE queries on the form, but if the user
changes other fields and then clicks that button, I get an error that the
data was changed elsewhere. Obviously this is because the form is not
committing the data changes before executing the UPDATE command. If I could
save the current record on the form before executing the UPDATE, that should
fix my problem.

Thanks,
Ryan
 
P

Philipp Stiefel

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam
please) said:
If (Me.Dirty) Then
DoCmd.RunCommand acCmdSaveRecord
End If

I'd prefer:

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


Cheers
Phil
 
V

Vadim Rapp

PS> I'd prefer:

PS> If (Me.Dirty) Then
PS> Me.Dirty = False
PS> End If

Though dirty=false indeed forces an update, Access documentation does not
say so:

"You can use the Dirty property to determine whether the current record has
been modified since it was last saved" . _Determine_. Not a word that it can
be _set_ and what would that mean. Even more: from the following sentence in
the same Help article, it appears that setting dirty=false by the code
should _prevent_ saving the record:

"For example, you may want to ask the user whether changes to a record were
intended and, if not, allow the user to move to the next record without
saving the changes." . Note that it does not mention Undo method.

I think all this qualify as undocumented feature, so it may work differently
in any future version. I would not use Dirty property other than for
reading-only.


Vadim Rapp
 
P

Philipp Stiefel

Vadim Rapp said:
PS> I'd prefer:

PS> If (Me.Dirty) Then
PS> Me.Dirty = False
PS> End If

Though dirty=false indeed forces an update, Access documentation does not
say so: [...]

I think all this qualify as undocumented feature, so it may work differently
in any future version. I would not use Dirty property other than for
reading-only.

Well, you are probably right. I wasn't aware of the fact that the use of
Dirty=False to save a record is not really documented. I'm using it for
quite a while now and never had any problem with it yet. Nevertheless I
won't go on recommending it to other people.

After all, I have to admit that Dirty=False just by itself is really
ambiguous. It may save the record, undo the changes, or as well just
reset the Dirty-Flag without doing anything to the data.

Thanks for pointing me to that issue!
Best wishes
Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top