John W. Colby
jwcolby at colbyconsulting.com
Tue Feb 24 15:54:54 CST 2004
I added rudimentary validation code to my text and combo framework classes today, and a validate function to my form class. As I call a ValidationSetup method of the form class I pass in the control name and message text. Since I have a control scanner that finds every object (with a class) and loads a class instance for each such control, as I call the ValidationSetup I grab a pointer to the instance of the class for that control and place the pointer in a colValidate collection keyed on the control's name. When I am finished setting up the validation for any controls I want to validate I have a collection with exactly and only the control classes that need their Validate method called. Now I can do code like: sub myform_Open(Cancel) with fdclsFrm .ValidationSetup "txtCtlName1", "Last Name" .ValidationSetup "cboCltName2", "Title" end with end sub Having done that there form events are sunk in the form class so BeforeUpdate calls the validate event for each control in the colValidate collection passing in Cancel. If Cancel comes back True, the collection iterator exits, and cancel True is passed back to the BeforeUpdate which prevents the record from being saved. The control's Validate method does things like put up a message informing the user that they need to enter data in a control and sets the focus in that control. Likewise the setup code causes the background color of any validated control to be set to a specific color so that all controls needing validation are visually distinct. Works swimmingly and now validating controls is a simple line of code for each control to validate that "does it all". John W. Colby www.ColbyConsulting.com