'Me.Dirty = False' statement

M

mscertified

I'm using the Me.Dirty = False statement to force saving an uncommited
record, however, I am getting error 2101 "The setting you entered isn't valid
for this property", what could cauyse this? When I press Help, I get a blank
screen. Thanks.
 
E

Evi

Put an apostraphe in front of any error trapping code (on error proceed or
On Error Go To)
and see which line of your code Debug highlights.
Evi
 
D

Dirk Goldgar

mscertified said:
I'm using the Me.Dirty = False statement to force saving an uncommited
record, however, I am getting error 2101 "The setting you entered isn't
valid
for this property", what could cauyse this? When I press Help, I get a
blank
screen. Thanks.


I don't believe I've seen that particular message under those circumstances,
but maybe the record in question can't be saved at the moment, because it
fails some validation constraint, or would produce a duplicate value in a
unique key field, or for some other reason. Make sure that the record in
question can be saved manually or via RunCommand acCmdSaveRecord. You may
want to try the RunCommand method temporarily, just to get a more
informative error message.
 
M

mscertified

Have already done that, and it is pointing to the 'Me.Dirty = False' statement.
 
D

Douglas J. Steele

In what event have you got the statement?

You can't use it, for example, in the BeforeUpdate or BeforeInsert events.
 
M

mscertified

It's not directly in an event procedure.
I'm reading data from a queue table into my form via a command button Click
event.
When I have finished populating the data, I wanted to force a commit so the
user could not erase the record by pressing escape.
I think what is happening is that I have related records missing, but I dont
know why I don't get a more conventional message. I have also gotten a 'There
is no current record' message on the 'Me.Dirty = False' statement. For now, I
have removed this statement and all works as I want.
 
A

Allen Browne

It means there is a reason why the record cannot be saved.

The form's Dirty property indicates that there are uncommittted edits in
progress in a form. Access sets the property to True as soon as you start
editing a bound control in a form.

When you set the property to False, Access responds by saving the record.
But that may not succeed. For example, if a required field is missing, or a
duplicate index is violated, or a validation rule is not met, or if you
cancel Form_BeforeUpdate, then Access cannot save the record. In this case,
the attempt to set Dirty to False fails. VBA then informs you that setting
the property did not work. The message is not very clear, but that's what it
is trying to tell you.

Consequently, any code that attempts to save the record needs to use error
handling. In the error handling you will want to trap error 2101 (and maybe
also some others such as 2115 and 3314), and give the user a more meaningful
message, e.g.:

Select Case Err.Number
Case 3314, 2101, 2115 'can't save.
strMsg = "Record cannot be saved at this time." & vbCrLf & _
"Complete the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, strCallingProc
...

Since this is needed in many places throughout an application, it makes
sense to create a generic error handler function that you call from all your
procedures, and you can develop these specialized error handling routines in
the one place (e.g. you may want to ignore error 2501, or catch error 0.)
For an example, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

The other possiblity is that you have attempted to use the Dirty property
for an unbound form. That fails with a different error.
 

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

Similar Threads


Top