validaition check... urgent...
hey all!
please help me to check for validaiton such that... i hv few textboxes and combo boxes and if data is not entered in them then the submit button should be locked... and also tell me where should i write the code as in .... in form_load or submit_click... im confused... the code i wrote was...
If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
MsgBox "Please fill all details"
SUBMIT2(1).Enabled = False
Else: SUBMIT2(1).Enabled = True
End If
thanks a tonne... plz do help!
good day!... enjoy programming!...
smile4evr
Junior Poster in Training
53 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
Submit or Ok-button is the proper place to validate input. Since you have many things to validate, I would use a separate function:
Private Function ValidateForm() As Boolean
' Validate form fields
If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
MsgBox "Please fill all details"
ValidateForm = False
Exit Function
End If
ValidateForm = True
End Function
and in the Submit or Ok-button validate:
Private Sub Command1_Click()
' Ok-button, validate before exit
If ValidateForm Then
' Fields are ok, return from the form
Me.Hide
End If
End Sub
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
thanks a lot for the responses... but its not working... i tried each of them invidually... but it is not working...
sorry... pls do keep helping!
thnx!
smile4evr
Junior Poster in Training
53 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
No. None of them is a complete solution and nobody can give one without seeing the whole code.
There may be a just a little spot everyone's missed. Can you give more details?
But few things to try out:
Text may contain spaces, so trim them off like Trim(cname.Text) = ""
Then split your validation code to validate every control separately:
If Trim(cname.Text) = "" Then
MsgBox "Please fill all details (cname)"
End If
If Trim(empname2.Text) = "" Then
MsgBox "Please fill all details (empname)"
End If
... etc.
and tell us at which point validation fails and what was the input. You may do validation in any of the suggested places (Ok_Click, Form_Unload etc.).
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
smile4evr said there are also combo boxes. Could the validation fail with combos?
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
thanks a lot! the problem has been solved!!
very sorry for late response!!
smile4evr
Junior Poster in Training
53 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2