Best Practice Form Validation (1 Viewer)

Tupacmoche

Registered User.
Local time
Today, 10:59
Joined
Apr 28, 2008
Messages
291
Hi Form Masters,

I have a form (see attached) that does not validate all sections. For example, there are three sub-forms placed on top of each other. The radio buttons un-hide each of the sub-form (Gift Allocation, Associated Credits, and Notification) when selected and hides the others. As, I understand after a sub-form gets focus and then on Lost Focus fires the validation code. But, some users are just skipping the sub-form. How can, I enforce validation in that situation.

Additionally, this main form has five (5) tabs which each need validation. Of course multiple tabs are considered part of the main form. So, my question with regard to the tabs is should the validation be done when on the tab or as an over all form validation (Best practice). Any suggestions on the best approach is appreciated.;)
 

Attachments

  • Egate Master (Main) Form.jpg
    Egate Master (Main) Form.jpg
    90 KB · Views: 39

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,478
Hi. For validating forms, it is considered "best practice" to use the form's BeforeUpdate event. However, if by "validating" you mean also to make sure the form was updated, then the BeforeUpdate event won't catch that. You'll have to use something else or in addition to it.
 
Last edited:

Tupacmoche

Registered User.
Local time
Today, 10:59
Joined
Apr 28, 2008
Messages
291
But what about the issue of the sub forms. If a user does not even enter them the values will be empty and since the form never gets focus the event trigger will never fire to validate. Any suggestion on how prevent that from happening?:eek:
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 10:59
Joined
Oct 17, 2012
Messages
3,276
Have your trigger update a global variable for each form, or maybe some bitwise code (1 = a, 2 = b, 4 = c, add 'em) indicating which forms were viewed and which werent.

Then, when they go to move on, check the globals to see if everything got checked.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:59
Joined
Oct 29, 2018
Messages
21,478
Ah, that's a catch-22 scenario for bound forms. If the user does not enter any data in the subform, you can use DCount() to check the underlying table to see if there's any matching data. However, once the user tries to enter any data in the subform, the main form's BeforeUpdate event will fire to validate it, so any validations for the subform performed on the main form will negate the changes the user is attempting to make on the subform. If you must ensure a parent and child record both exists, then you may have to go the unbound form route.
 

Minty

AWF VIP
Local time
Today, 15:59
Joined
Jul 26, 2013
Messages
10,371
Not easy. You can't force a check based on the main forms beforeupdate, as if you go to the sub form to enter new data that already fires...

Another other route would be to force a popup modal form into the mix and ensure it was completed for the child records.

Maybe force the user onto the correct subform based on a certain mainform field being completed. Once on the subform then you can validate away.
 

Tupacmoche

Registered User.
Local time
Today, 10:59
Joined
Apr 28, 2008
Messages
291
Minty,

You have given me an idea. After the user completes the payment method, I can code so that the user is put into the sub form via vba code. The balance is easy once in the sub form the After update event takes over to ensure that the data is not blank. Super!:)
 

Users who are viewing this thread

Top Bottom