Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating Info Question... 1

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
I am trying to validate all the user input before I save it. I have been using the Else/If and it turned out very messy and hard to follow/edit. Any suggestions on a better way to go about this?

It looks something like this

If not valid name then
error
else
if not valid ssn then
error
else
if not blah blah and so on...
endif
endif


thank you!
 
I would get rid of the else's.

For example, in a cmdSave routine, insert a line:
If Validate Then
SaveData
Endif

Then write a validation function more like this:
Private Function Validate() As Boolean
' Function to validate all data.

Validate = False
If txtName.Text = vbNullString then
msgbox "Name not OK
txtName.Setfocus
Exit Function
End If

If txtSSN.Text = vbNullString Then
msgbox "SSN not OK
txtSSN.Setfocus
Exit Function
Else
' Check length, etc. here
End If


' If you get here, data is OK
Validate = True


End Function
 
thanks, will try it right now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top