Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
Subject: Visual Basic Form Validation
Question:
Hi,
I am writing an application with a
lot of forms. Each form can contain
multiple input fields such as text boxes,
check boxes, combo etc.
My question is:
I want to write a global code to
which i could pass a form. I can also
pass the fields which need validation
as parameter to the global
function/code.
The function should then bring
up a message box saying that the user needs
to complete all following fields
and change the back color of the fields
which need to be completed.
I have
seen may such codes on the web, but the problem i face with them is
that they
bring up a message for every field, which could be annoying if a
lot of
fields need validaion. There should be just one message for any
number of
fields and the user has to complete these before going further.
Please help
me with some code or examples that you may have.
Many
thanks.
Girish
Answer:
Girish,
In your public function, write:
Public Function ErrorMsg() as Boolean
If form1.textbox1.text = “” Or form1.textbox2.text = “” Or …
Then
msgbox (“You didn’t finish completing your form!”)
ErrorMsg = False
Else
ErrorMsg = True
End If
End Function
This function returns False if the user forgot one or more
fields (and in that case gives an error message) and True if it’s o.k. If you
have an array of textbox objects you might as well write: Public Function
ErrorMsg() as Boolean
Incomplete as Boolean
Incomplete = False
For I = 0 to ObjectsNumber
If form1.textbox1(I) = “”
then
Incomplete = True
Next I
If Incomplete = True
Then msgbox (“You didn’t finish completing your form!”)
ErrorMsg = False
Else
ErrorMsg = True
End If
End Function
Home Page - Categories - Forms - Visual Basic Form
Validation
Copyright 2002 All rights reserved to
vb4all.8m.net
* By clicking the 'Click here' link you agree to
our downloading terms.