Visual Basic Database Tutorial - Part 6
Cliff Richard once had a number one hit that began, "Congratulations (strum, strum) and Validations (strum, strum) lah lah lah dadada lah lah dada la lahhh!".
Actually, no, he didn't. In fact, those fictional lyrics weren't even remotely plausible. But nevertheless, it introduced the next section validation which is itself rather abstract.
You see, it doesn't really fit anywhere within my grand plan to boost your database knowledge. And that's why I'm going to include it here.
[Ed: I see... clear as mud]
Now, many of the common controls have a 'CausesValidation' property, which is set to True by default. This means before a user leaves the Text Box or Combo Box or whatever, the Validation event is fired.
And it's there you can check what they entered. For example, I placed the following code behind my txtBreed button from the project on the last page:
Private Sub txtBreed_Validate(Cancel As Boolean) If Trim(txtBreed.Text) = "Unknown" Then MsgBox "Can't accept that. Are you sure " & _ "it's not an iguana?" Cancel = True End IfEnd Sub
If a user enters 'Unknown' into the Breed Text Box, my code tells the Text Box the value provided is unacceptable by setting the passed Cancel value to True. And that means the focus remains on the Text Box in which the problem occurred.
If I performed no checking or set Cancel to False, the user would've been able to continue in their operations.
So the Validate event is neat for verifying information a user enters; whether you want to ensure they've typed a sensible number or you need to perform a little syntax checking, it's a pretty cool event to have around. In fact, it's cooler than Mr Cool the Cola Bear, winner of last year's I'm-Sooo-Cool competition.
[Ed: Hmm, no]
[Karl: <Tears> ]
Page 4 of 6