Form Validation aka Am I cracking up (1 Viewer)

theDBguy

I’m here to help
Staff member
Local time
Today, 10:47
Joined
Oct 29, 2018
Messages
21,467
Yeah I think you got them but this still doesn't quite work.
This scenario is unlikely to happen on this form but it could on others.
So user goes in and blanks the description out only. He then tries using the combo box to skip to another record. The logic tells him there is an error and sets description back to old value. All good so far. Now this could happen if the user is ham fisted and hits the space bar when the description is highlighted. So what is the problem? If the user then tries to go to skip to another record now using the combo box he hits the code "If Me.Dirty Then Me.Dirty = False" wich takes him into the code beforeupdate which updates the updateby and updateon fields when it shouldn't . In this sceenario I Think the beforeupdate event is triggered as well if the user uses the close or navigation buttons.

So why, in this case, is the form dirty if the field has been reset to the old value. Is there way of 'undirtying' the form at this stage?
Hi. When the user hits the spacebar when the field is highlighted, doesn't it replaces the old value with a space? If so, then "in this case," the record was updated or changed, that's why the form is Dirty. What do you expect to happen in this scenario, where the user replaces the old description with a space? Would you like to reset it back to the old value and not allow the space? Or, would you like to accept the single space as a description but not update the Updated By and Updated On fields?
 

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Hi. When the user hits the spacebar when the field is highlighted, doesn't it replaces the old value with a space? If so, then "in this case," the record was updated or changed, that's why the form is Dirty. What do you expect to happen in this scenario, where the user replaces the old description with a space? Would you like to reset it back to the old value and not allow the space? Or, would you like to accept the single space as a description but not update the Updated By and Updated On fields?

Yes it does and when you try and skip to a different record with the combo box you get an error and the value is set back to what it was. If you then skip to a new record the updateby and on are updated when effectively the record hasn't changed
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:47
Joined
Oct 29, 2018
Messages
21,467
Yes it does and when you try and skip to a different record with the combo box you get an error and the value is set back to what it was. If you then skip to a new record the updateby and on are updated when effectively the record hasn't changed
Okay, I think I understand. Unfortunately, the only way to reset the Dirty property of the form is to Undo it, which means any other changes will also reset. For your complex forms, you may have to perform the auto-save and cancel in each updatable control's particular event rather than waiting until the form's event at the end. In other words, instead of doing a "catch-all" validation, you may have to do individual validations. Just a thought...


PS. Another thought is to store the initial state of the form into memory and then compare it with the current state when the form's BeforeUpdate event fires. So, even if the user makes any changes, which sets the Dirty property to True, if the initial and current states match, then nothing will be harmed when you issue a Me.Undo, which would then preserve the UpdateBy/On values.
 

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Okay, I think I understand. Unfortunately, the only way to reset the Dirty property of the form is to Undo it, which means any other changes will also reset. For your complex forms, you may have to perform the auto-save and cancel in each updatable control's particular event rather than waiting until the form's event at the end. In other words, instead of doing a "catch-all" validation, you may have to do individual validations. Just a thought...


PS. Another thought is to store the initial state of the form into memory and then compare it with the current state when the form's BeforeUpdate event fires. So, even if the user makes any changes, which sets the Dirty property to True, if the initial and current states match, then nothing will be harmed when you issue a Me.Undo, which would then preserve the UpdateBy/On values.

I'm coming t the same conclusion!!
I have found a demo that forces the user to save the record by clicking a button but I can just imagine there will be one case where it doesn't work.
Think I've spent to much time on this, as have you, so will pick the version that is most likely to happen and screw the .1% where it will give faqlse results. Appreciate your patience and help. Thanks a million.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:47
Joined
Oct 29, 2018
Messages
21,467
Hi. This may not necessarily apply to your real application but I think it works for the demo file you posted. Hope it helps...
 

Attachments

  • demofor delete(3).accdb
    636 KB · Views: 38

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Hi. This may not necessarily apply to your real application but I think it works for the demo file you posted. Hope it helps...

OK I'll check that out, probably next week now, but in the meantime the attached seems to work. The idea was stolen from this link! https://access-programmers.co.uk/forums/showthread.php?t=38364

You have to save the record first or undo. It's slightly more work involved for the user but for the more complex forms will be ideal
Would be better not to have user do a manual save/undo but if that's what's needed then....
 

Attachments

  • tax saveme version.accdb
    736 KB · Views: 36

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Hi. This may not necessarily apply to your real application but I think it works for the demo file you posted. Hope it helps...

Just had a quick look and from first test looks good. THanks. I'll give it more of a hammering and then apply to one of the more complex forms to see how it fares. Thanks for your help!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:47
Joined
Oct 29, 2018
Messages
21,467
Hi. Good luck! Please let us know how it goes.
 

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Hi. Good luck! Please let us know how it goes.


OK I'm applying it some more complex forms regarding validation etc etc. I'm pretty sure I know what's going on except for sub Form_Current. Is this just opening and closing the table that the form is bound to using the ID. I have one table with it's own ID and IDs from other tables and want to make sure I know which one to use!!
 

ryetee

Registered User.
Local time
Today, 18:47
Joined
Jul 30, 2013
Messages
952
Hi. Good luck! Please let us know how it goes.


BIG EDIT HERE AS I'VE WORKED IT OUT!!

I think there is a potential problem with RecordMatch. I found this when a self inflicted error rose it's ugly head. If there are any problems within RecorDMatch a boolean gets set to false and the code gets exited with RecordMatch = result. In the case of a system error this gets bypassed so in the error handler I set the boolean to false and exited with RecordMatch = result. However this doesn't seem to work and it appears RecordMatch is set to true. Any ideas?


If ValidateForm = True Then
If RecordMatch() Then '<=========this is true if there is a system error in RecordMatch
Else
Me.UpdatedBy = pubUserName
Me.[Date Updated] = Now()
End If
Else
Cancel = True
End If
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 10:47
Joined
Oct 29, 2018
Messages
21,467
Hi. Sorry for the delay. I am currently on travel. Glad to hear you worked it out. Cheers!
PS. You might consider posting your solution in case it might help others as well.
 

Users who are viewing this thread

Top Bottom