Afterupdate Problems

geraldcor

Registered User.
Local time
Today, 15:54
Joined
Jan 26, 2004
Messages
145
I have a form. On this form is a field that I want to update when the user changes a field on the form (a sort of tracking feature). I can't get the on update event to run when I change a record. The only time it runs is when I click the Close button. This is no good because you can open the form and not change anything and it will still show that the record has been changed. How do I run some code when the record has changed?

Greg
 
You can also use the form's BEFORE UPDATE event as it will not fire unless the form has had data changed or added.
 
Here is the oddity. I tried setting a checkbox to true on the ondirty and beforeupdate and afterupdate but the checkbox would never update. I would enter something into a field, exit the field and the checkbox remains false.

Does it matter if MySQL is the backend?
 
If an event isn't firing then a lot of times the form is corrupt. I would see if importing everything into a new, blank mdb file will help.
 
Out of curiosity, is the checkbox bound to a field in the table or query which serves as the recordsource for your form?
 
The checkbox is not bound to anything. It is used as a debugging thing. The afterupdate event gets called when I click the Close button and the checkbox becomes true, then the form closes.

Corrupt form? It works well in all other regards. How could it be corrupt?
 
The checkbox is not bound to anything. It is used as a debugging thing. The afterupdate event gets called when I click the Close button and the checkbox becomes true, then the form closes.

Corrupt form? It works well in all other regards. How could it be corrupt?

Corruption can start creeping in and doesn't necessarily disable everything right away. You can have a corrupt form but most everything works but some doesn't. If it is corrupt it will only get worse, but when is hard to say.

If you have code on an event and the event SHOULD occur (can verify by putting a message box on the event) and it doesn't, then the form is corrupt and you should quickly rescue everything before it gets worse. If you import everything into a new, blank mdb file and then the event works, that is great. If you import everything into a new mdb file and it still doesn't work, then you might still be suffering from corruption, but it could be something else. So, a quick test by importing into a new file is a quick, and easy, way to see if you can effect a fix.
 
Well, I don't know Gerald. I just tested an unbound checkbox on a form with some fields bound to a table. I used the code

Me.checkbox49 = -1

in the forms on_dirty event and as soon as I started typing in any of the bound fields, it did what is was supposed to.

So if yours ain't doing it, then I'm guessing the Bob is right and something has become corrupted in your form.
 
I'm speaking from experience on this one. I have had that exact issue before and I solved it by importing to a new mdb file.
 
Okay. So I imported it into a new mdb file and that did nothing. I made a new form that is bound to a table and put on an unbound check box and I did me.check3 = -1 on both on dirty and on update events and nothing happened when I typed. HOWEVER, when I used the record selectors at the bottom of the form to scroll to another record the checkbox became true. It seems it is not committing changes until I leave the record.

Any thoughts on this?

P.S. Thanks for hanging on with me for this one.
 
Any way you can post your db (remove any sensitive info) so we can run some tests?
 
Here is a small portion of my db with only a few non-important records. I have the test form I made as well as the problem form (frmContacts). If there is a way to delete this attachment once it has been looked at that would be great. If not, so be it.
 

Attachments

Which checkbox am I looking at?

EDIT:

Never mind, I re-read the orignal post and figured out that I wasn't looking for a checkbox but the update of the form.
 
Okay Gerald:

First of all, the AfterUpdate events are firing and the checkbox is getting updated (it happens when you move to another record because that's when the form's after update event occurs. The problem as I see it is that your checkbox isn't bound to a field to be able to store that a particular record has updated.
 
The field does not need to be bound because it just needs to be true when the user clicks the close button. I don't want the record to remember that it has been updated. This is going to be used as a way to log if a record has been changed.

So if afterupdate is called after you move off a record then I suppose that is ok as long as I am able to work the logic out. How is craigDolphin making the ondirty event work so that it shows the record as updated right when he starts typing.

I will try a few different things and see if I can get it working.
 
The problem is, if the checkbox is not bound then having it updating is not really helpful because it will only show up if you move to another record. However, as it is unbound it will stay checked for the next record. So, I think the On Dirty event may be the one you will want. As for making something visually able to be seen that the form has been edited, I think there would be a better way than a small checkbox which seems to be not overly visible among all of the other controls.

What I would do is to change the color of the detail section of the form if the form has been dirtied and then reset it in the On Current event of the form. Then it really is visually able to really easily see that the form has been changed.
 
I used the on_dirty event to set the checkbox as described earlier.
 
I can't get the on_dirty event to call at all. I type in a field and my checkbox isn't checked and my message box doesn't message. I feel like a fool with all of this.

The problem with the afterupdate only being called when I change a record is that I want it called when the form is closed. I want to populate a field in a table based on whether or not the form was updated.
 

Users who are viewing this thread

Back
Top Bottom