In a perfect world, your code would run correctly every time.
You will first see the programming you can use to handle errors, and then you will see how to use validation techniques to prevent bad data from being entered into your application in the first place.
A name doesn't generally contain weird symbols, and definitely not numbers. This can be from the mouse clicking inside another field, or a Tab key being pressed to navigate to the next input control. ") Else Email Valid = True 'Email is Perfect End If Else 'Not A Match To Pattern Email Valid = False 'Set Boolean Variable To False Message Box. I hope you have learned from this article and that you have enjoyed it as much as I did.
That may seem like Captain Obvious speaking, but you'll be amazed at some of the data that gets entered into a name field. I then created an If statement to determine how the input data was formatted and whether or not the data is only alphabetic.
The Not In List event occurs after the keyboard events and the Change events for the combo box, but before the events for any other control or the form.
In most cases, these functions and objects duplicate functionality that you can find in other namespaces in the . They are necessary only when the Visual Basic 6.0 code model differs significantly from the .
VB6 namespace are provided for use by the tools for upgrading from Visual Basic 6.0 to Visual Basic.
Figure 1 - These objects will determine if all our data is valid or not. Clear() 'Clear Text Box Name Valid = False 'Boolean = False Else Name Valid = True 'Everything Fine End If End Sub Easy one to start with. Focus() 'Set Focus To Text Box End If End Sub Private Sub txt Email_Lost Focus(sender As Object, e As System. Lost Focus Validate Email() 'Check Email Validity End Sub The expression may look horrible to the layman's eye, but look closer. To check if the user has entered an email that actually exists, you will have to find a different way such as to send a of some sorts.
Based on each of these variables' values, we will know if the data is correct or not. The Leave event fires when the control loses focus. As you can see, Regular Expressions are a vital tool to have at your disposal, so become good friends with them.