Form Data Validation.doc

  • Uploaded by: JOSE ANGEL
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Form Data Validation.doc as PDF for free.

More details

  • Words: 1,192
  • Pages: 3
Form Data Validation If you ever need to make sure the user entered valid information on the form before committing the data into the table, then it is considered "best practice" to perform data validation routines using the Form's BeforeUpdate event. In addition, it is common practice to use the Tag property of form controls to indicate which data needs to be validated. Si alguna vez necesita asegurarse de que el usuario ingresó información válida en el formulario antes de ingresar los datos en la tabla, se considera una "mejor práctica" para realizar rutinas de validación de datos utilizando el evento BeforeUpdate del formulario. Además, es una práctica común utilizar la propiedad Etiqueta de los controles de formulario para indicar qué datos deben validarse.

For example, let us say you have a form for a loan application and a complete section must be filled out for a co-borrower information when the customer is applying for a joint loan. Using the Tag property approach, you can enter "co-borrower" in the Tag property of each Textbox representing co-borrower information and then use the following code in the Form's BeforeUpdate event: Por ejemplo, supongamos que tiene un formulario para una solicitud de préstamo y se debe completar una sección completa para obtener información de un coprestatario cuando el cliente está solicitando un préstamo conjunto. Utilizando el enfoque de propiedad Tag, puede ingresar "coprestatario" en la propiedad Tag de cada Textbox que represente la información del coprestatario y luego utilizar el siguiente código en el evento BeforeUpdate del formulario: If Me.LoanType = "joint" Then For Each ctl In Me.Controls If ctl.Tag = "co-borrower" Then If IsNull(ctl.Value) Then Cancel = True MsgBox "Please complete co-borrower information.", vbInformation, "Required" Exit For End If End If Next End If

As already mentioned, this approach is common practice and usually applies to probably 99% of situations for data validations. However, someone approached me recently and said this approach of using the Tag property and looping through all the form controls made his form ran very slowly. It turns out his form was very busy with multiple subforms and a lot of unbound controls updated using code to reflect specific information about the current record from other tables in the database. Como ya se mencionó, este enfoque es una práctica común y generalmente se aplica probablemente al 99% de las situaciones para la validación de datos. Sin embargo, alguien se me acercó recientemente y dijo que este enfoque de usar la propiedad Etiqueta y recorrer todos los controles de formulario hacía que su formulario funcionara muy lentamente. Resulta que su formulario estaba muy ocupado con múltiples

subformularios y una gran cantidad de controles no vinculados actualizados utilizando código para reflejar información específica sobre el registro actual de otras tablas en la base de datos.

So, in this case, we want to avoid looping through all form controls, which is a requirement when using the Tag property approach. To do so, we'll need to know the names of the controls to evaluate, so we can simply validate them. One of the main advantages of using the Tag property is it is very easy to add or remove controls to validate without needing to modify the code. If we hard code the names of the controls to validate, we'll need to modify the code each time our requirements change. Por lo tanto, en este caso, queremos evitar el bucle a través de todos los controles de formulario, que es un requisito cuando se utiliza el enfoque de propiedad Etiqueta. Para hacerlo, necesitaremos conocer los nombres de los controles para evaluar, así que simplemente podemos validarlos. Una de las principales ventajas de usar la propiedad Tag es que es muy fácil agregar o quitar controles para validar sin necesidad de modificar el código. Si codificamos los nombres de los controles para validarlos, tendremos que modificar el código cada vez que cambien nuestros requisitos.

As an alternative, we need to somehow store the names of the controls to validate and then go through each of them to check the form's data. There are several options to accomplish this task. For example, we can use a hidden unbound Textbox to store a comma-delimited value of control names to validate, We can then use the Split() function to store the control names in an array for validation. Como alternativa, tenemos que almacenar de alguna manera los nombres de los controles para validar y luego revisar cada uno de ellos para verificar los datos del formulario. Hay varias opciones para lograr esta tarea. Por ejemplo, podemos usar un cuadro de texto desacoplado oculto para almacenar un valor delimitado por comas de los nombres de control para validar. Entonces podemos usar la función Dividir () para almacenar los nombres de control en una matriz para su validación.

The approach I will demonstrate will use a hidden unbound Listbox to store the control names. I like using a Listbox because it is very easy to loop through each item in a Listbox when performing our data validation. For this approach, I recommend using a Value List for a Row Source, although using a table will work just fine as well. Assuming the Bound Column of the Listbox is set to the column with the names of the control, here's a modified version of the above code using a Listbox rather than the Tag property: El enfoque que demostraré usará un Listbox desenlazado oculto para almacenar los nombres de control. Me gusta usar un Listbox porque es muy fácil recorrer cada elemento en un Listbox al realizar nuestra validación de datos. Para este enfoque, recomiendo usar una lista de valores para un origen de fila, aunque usar una tabla también funcionará bien. Suponiendo que la columna enlazada del Listbox está configurada en la columna con los nombres del control, aquí hay una versión modificada del código anterior que utiliza un Listbox en lugar de la propiedad Tag: If Me.LoanType = "joint" Then For lngItem = 0 To Me.ListboxName.ListCount - 1 If IsNull(Me.Controls(Me.ListboxName.ItemData(lngItem))) Then

Cancel = True MsgBox "Please complete co-borrower information.", vbInformation, "Required" Exit For End If Next End If

As you can see, this alternative approach accomplishes the same task as using the Tag property without affecting the speed of a very busy form. Adding or removing controls to validate is also as simple as updating the Listbox without needing to alter the code. This approach can even be expanded by storing all control names in a table along with the name of the form or forms to which the control validation applies. Doing so will allow the same code to validate multiple forms. Como puede ver, este enfoque alternativo cumple la misma tarea que usar la propiedad Tag sin afectar la velocidad de una forma muy ocupada. Agregar o quitar controles para validar también es tan simple como actualizar el Listbox sin necesidad de modificar el código. Este enfoque incluso se puede expandir almacenando todos los nombres de control en una tabla junto con el nombre de la forma o formularios a los que se aplica la validación de control. Hacerlo permitirá que el mismo código valide múltiples formularios.

Related Documents

Data Form
November 2019 28
Personal Data Form
November 2019 16
Form Data Seragam Ngm.docx
December 2019 21
Form Data Balita.xlsx
June 2020 10
Bio Data Form
July 2020 6

More Documents from ""

Form Data Validation.doc
November 2019 16
Lopez-milla-julian_6.pdf
December 2019 15
Antecedentes.docx
December 2019 5